Remove time from Date Time field

jeremyjameshans
Mega Guru

Hello,

I would like to strip out the time on the Due Date field for my Catalog Tasks.

 

My script to populate is very simple: 

 

task.due_date = current.variables.requested_date.getDisplayValue();

 

Is there a way to strip out the time? 

I have tried getLocalDate() and failed badly. 

 

1 ACCEPTED SOLUTION

jeremyjameshans
Mega Guru

Thank you Arthur,  that is good advice. 

View solution in original post

6 REPLIES 6

Lansford Hazel
Giga Expert

Due date is a date time field you can't remove the time. The best option is probably to set it to the end of the day.

Parneet1
Tera Expert

LJ Hazel is correct. Due Date is a Date Time field. If you want to capture just the date, creating a new 'Date' type field would be one option. Otherwise, you can set Due Date to a specific time.

jeremyjameshans
Mega Guru

What would the code look like to add 12 hours?

 

asifnoor
Kilo Patron

If the due date is date/time, then you cannot just populate date in it. Even if you try to do it, it will add 00:00:00 to the date and show it bcoz its a date/time field.

However, if you want to fetch only date from the date/time field, then you can do like this.

task.due_date = current.variables.requested_date.getDisplayValue();
var gdt = new GlideDateTime(current.variables.requested_date).getDate();
gs.print(gdt);

Mark the comment as a correct answer and also helpful if it helps.