Function GetValue() returns data not in date format

I need to get date from a cell but function GetValue() keeps returning data in standart format.
example: 06.12.2023 but it returns 45266
Basicaly I need to get it and put in a Date variable.
What can I do in this situation? Should I use other function or is it api issue?


Hello @AlexAndr

You have to additionally set number format for the cell with method SetNumberFormat.
Here is a small example:

var oSheet = Api.GetActiveSheet();

var dataValue = oSheet.GetRange("A1").GetValue();

oSheet.GetRange("C3").AutoFit(true, false);

There is a date in cell A1 that is copied to variable dataValue , then pasted to the cell C3 and format is applied. Also I’ve added AutoFit method to avoid insufficient amount of space for the date that would cause date to be displayed like #####. The result is:

1 Like

Basically I was confused with what data GetValue() function keeps returning to me . I took me a while to understand that it returns the number of days that passed since 01/01/1900 :smiley: . It would be nice if it returned data in format that is represented in the cell actually , beacause it can be veeeery confusing especially for newbies like myself. But thanks anyways! P.S. Also I noticed that javascript counts days from 01/01/1970 not from 01/01/1900 , so it must be taken into account when someone write code. It would be nice if you mention that in the manual somewhere :slight_smile:

Indeed, JS counts days from 1970 but VBA does from 1900, please correct me if I’m wrong.

Pardon me , but dont get why you mentioned VBA .

VBA is used in various text processors like MS Office, Libre Office, etc. It is a starting point, so to provide even experience with macros, in our editors date count starts from 01/01/1900 just like in VBA.