Glidedate time giving wrong output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2018 11:20 PM
I am checking in background script value output of glidedatetime.
var myDate= new GlideDateTime('12/04/2018 13:34:23');
gs.print(myDate.getValue());
gs.print(myDate.getDisplayValue());
Output : 2018-12-04 yy-dd-mm
04/12/2018
var myDate= new GlideDateTime('13/04/2018 13:34:23');
gs.print(myDate.getValue());
gs.print(myDate.getDisplayValue());
Output : 2018-04-13 yy-mm-dd
13/04/2018
Can anyone explain why is the format changing from dd-mm to mm-dd in these two dates.
It is causing error as i need to calculate the day of the date and it is calculating false for these dates
getDateDifferenceExcWeekends: function(){
var firstDT = this.getParameter('sysparm_fdt'); //date with format dd/mm/yyyy
var gdt = new GlideDateTime(firstDT);
var days = gdt.getDayOfWeekLocalTime();
var day;
if (days == 1) {
day = 'Monday';
} else if (days == 2) {
day = 'Tuesday';
} else if (days == 3) {
day = 'Wednesday';
} else if (days == 4) {
day = 'Thursday';
} else if (days == 5) {
day = 'Friday';
} else if (days == 6) {
day = 'Saturday';
} else {
day = "Sunday";
}
return day;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2018 11:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2018 11:51 PM
Hi Monica,
The problem here is not the system settings.
The function is not able to differentiate between the date and month.
For 12/04/2018 - output is 2018-12-04
but for 13/04/2018 output is 2018-04-13.
So when the date is above 12 it is calculating fine, but for dates below 12, it is pushing month in the end instead of date.
So instead of calculating day of 12april , it is calculating day of 4dec
BTW the property in my system is set as the above shown in the screenshot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2018 11:55 PM
gs.print(myDate.getValue()); - The date and time in the internal format and system time zone.
gs.print(myDate.getDisplayValue()); - The date and time in the user's format and time zone.
You need to the convert them into the same format and timezone to do the correct calculation.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2018 02:55 AM
Hey avanis,
You just use this code after glide it will help you.
var now=new GlideDateTime(provide your time here);
var a= now.getDate().getByFormat('yyyy-MM-dd hh:mm:ss');//it will return format as i give in get format.
HOPE THIS HELPFUL!!!!! MARK CORRECT OR HELPFUL.
Thanks,
Mohammed Iqbal