Glidedate time giving wrong output

avanis
Kilo Contributor

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;
}

 

 

4 REPLIES 4

Monika2
Giga Guru

Hi Avanis,

Go to the system properties->Basic Configuration

there you fill find the date format select the same as per your requirement and save.

PFB screenshot for your reference

find_real_file.png

 

Hope that helps.

 

Regards,

Monika

avanis
Kilo Contributor

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.

Rahul Jain11
Kilo Guru

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

Mohammed_Iqbal
Tera Guru

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