Why an i getting Invalid Date on client script

Chetan Kumar
Tera Contributor

Its a OnChange Script 

var start = new Date(g_form.getValue('from_date'));
alert(start);

Type is "Date " for the variable
Error i'm getting : Invalid Date

Why am i getting this error, please help 

5 REPLIES 5

Community Alums
Not applicable

Hello,

What is the exactly requirement after getting the date? Could you please elaborate? Attached image is not visible.

-----------------------------------------------------------------------------------------

The setValue() and getValue() methods require parameters in the UTC time zone and internal format. Other formats may return invalid results.

The toString() method returns the same string as the getValue() method.

The setDisplayValue() and getDisplayValue() methods require parameters in the local time zone (user/system) and local format (user/system). Other formats may return invalid results.

//Example: If user’s date time format is MM.dd.yyyy HH:mm:ss

// Do this

var input = “08.05.2015 16:21:47”;
var gdt = new GlideDateTime();
gdt.setDisplayValue(input);

// Not this

var input = “08.05.2015 16:21:47”;
var gdt = new GlideDateTime(input);

 

-----------------------------------------------------------------------------------------

 

Reference article - KB0594664

 

Thanks & Regards,

Akshay

@Akshay Kangankar  just an FYI... the GlideDateTime API is a server-side API. It will not work in client scripts.

Community Alums
Not applicable

Hello,

Yes, correct. Most of the functions like Addition, subtraction, comparison of date done in server side. For that we can call script include from client script.

I was not aware what exactly author's requirement. I consider he need to do any of above function & hence I have provided above reference. 

John Dahl
Tera Guru

Check the value and type that you are getting form the form, before you try to create the date object: 

var fdate = g_form.getValue( 'from_date' );
alert( 'From Date is: ' + fdate + ' and is of type: ' + typeof fdate );

Make sure it's returning a string format that the JavaScript Date constructor can recognize.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date