1
votes

In google sheets when I insert a date it saves it in the right format when I get that value I get an int number I insert this 1/6/2021 & I get that 44202 1/6/2021 => 44202 how to convert this number to date in dart or java or any language

I get it from google sheets API using a package so it gives me a number

https://pub.dev/packages/gsheets

3
whats your question? - player0
how to convert this number to date - Abdelrahman Tareq
What language are you using? - Iamblichus
I use dart language - Abdelrahman Tareq

3 Answers

4
votes

44202 refers to the number of days passed since the epoch time used in spreadsheets, which refers to December 30th, 1899.

If you want to retrieve the corresponding date in Dart, you can just add this number of days to this epoch date. For example, you could do this:

var epoch = new DateTime(1899,12,30);
var currentDate = epoch.add(new Duration(days: 44202));
print(currentDate); // 2021-01-06

Reference:

0
votes

internaly:

enter image description here


externaly:

=TEXT(A1; "dd/mm/yyyy")

enter image description here

0
votes

Iamblichus's answer is the right answer but I'd like to add some details about how to convert hours, minutes and seconds, that I found on this Javascript answer:

var fractionalDay = serial - serial.floor() + 0.0000001;
var totalSeconds = (86400 * fractionalDay).floor();
var seconds = totalSeconds % 60;
totalSeconds -= seconds;
var hours = (totalSeconds / (60 * 60)).floor();
var minutes = (totalSeconds / 60).floor() % 60;

var epoch = DateTime(1899,12,30);
var currentDate = epoch.add(Duration(days: serial.floor(), hours: hours, minutes: minutes, seconds: seconds));