Date fields confuse month with day

Jose MMR
Tera Guru

Hi all,

 

I am working with datetime fields. I use a script to fill these fields but I found a bad behaviour.

 

I try to set value as 01/10/2024 (first of october) but systems set as 10/01/2024 (tenth of january).

 

In my script:

 

var date ="2024/10/01 00:00:00" (introduced by user and set here trying to be more clear)

var a = new GlideDateTime();

a.setDisplayValue(date, "yyyy-MM-dd HH:mm:ss")

 

Later on a gliderecord

...

gr.setValue("start",a);

gr.insert();

 

Could anyone have same problem in past?

Regards.

1 ACCEPTED SOLUTION

Mark Manders
Mega Patron

Always fun to fight with date/time, until it gets frustrating.

 

Can you see if this works for you (I am unable to reproduce your issue, so hoping it helps).

var userDate = "2024-10-01 00:00:00"; // Ensure consistent format yyyy-MM-dd
var a = new GlideDateTime();
a.setValue(userDate); // Use setValue() to directly set the value in ISO format

var grIncident = new GlideRecord('incident');
grIncident.initialize();
grIncident.setValue('start_date', a); // Set the GlideDateTime object directly
grIncident.insert();

 

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

3 REPLIES 3

Eshwar Reddy
Kilo Sage

Hi @Jose MMR 
Use below script 

var userInputDate = "01/10/2024"
var formattedDate = userInputDate.split("/").reverse().join("-") + " 00:00:00";
var a = new GlideDateTime();
a.setDisplayValue(formattedDate, "yyyy-MM-dd HH:mm:ss");

Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution

 

Thanks 
Eshwar



Hi Eshwar Reddy


Thanks for your answer. Unfortunatelly the problem continues. I can transform dates in script but in the moment to set to field, changes.

Mark Manders
Mega Patron

Always fun to fight with date/time, until it gets frustrating.

 

Can you see if this works for you (I am unable to reproduce your issue, so hoping it helps).

var userDate = "2024-10-01 00:00:00"; // Ensure consistent format yyyy-MM-dd
var a = new GlideDateTime();
a.setValue(userDate); // Use setValue() to directly set the value in ISO format

var grIncident = new GlideRecord('incident');
grIncident.initialize();
grIncident.setValue('start_date', a); // Set the GlideDateTime object directly
grIncident.insert();

 

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark