Why an i getting Invalid Date on client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2022 04:56 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2022 08:31 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2022 09:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2022 09:13 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2022 09:05 AM
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