This is a migrated thread and some comments may be shown as answers.
Convert Cell value to javascript/JSON date
2 Answers 21 Views
This is a migrated thread and some comments may be shown as answers.
Armando Canez
Top achievements
Rank 1
Armando Canez asked on 26 Apr 2018, 06:28 PM

Hi!

I'm having a hard time using the jQuery spreadsheet  to give me a date value in javascript.

after a button click I need to get the value of a cell as a date object. However the range.value() returns a number (not epoch or milliseconds.)

 

//set the value
currentSpreadsheet.activeSheet().range("A1").value(new Date('01/01/2018')) // no problem here
 
var cellValue = currentSpreadsheet.activeSheet().range("A1").value() // in this case, cellValue returns 43101. I need the date. (01/01/2018 in this case)

 

 

How do I convert cellValue to a javascript date?? ... or how do I access the cell so it gives me the date value? I'm not familiar how to convert this number to a Date object.

 

Cell definition (all of this works fine. I only want to get the value and convert it to date):

{
format: kendo.culture().calendar.patterns.d,
transform : function(val){
  if (!val) return '';
     return (new Date(val));
 }
validation :{
                             dataType: "date",
                             showButton: true,
                             comparerType: "between",
                             from: 'DATEVALUE("1/1/1900")',
                             to: 'DATEVALUE("1/1/2100")',
                             allowNulls: !esRequerido,
                             type: "reject",
                             titleTemplate: " bla bla",
                             messageTemplate: "Bla bla"
                         }

 

Any help will be appreciated.

Armando

2 Answers, 1 is accepted

Sort by
0
Armando Canez
Top achievements
Rank 1
answered on 26 Apr 2018, 07:52 PM

Solved It.

For all the ones looking for the answer, The returned value is the number of days since 01/01/1900. (Not including the current day. That's why the - 1)

var jsonDateValue = new Date((new Date('01/01/1900')).setDate(cellValue - 1)).toJSON();

 

 

 

 

0
Dimitar
Telerik team
answered on 27 Apr 2018, 02:23 PM
Hello Armando,

Thank you for sharing your solution.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Asked by
Armando Canez
Top achievements
Rank 1
Answers by
Armando Canez
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or