Covert DateTime format to date only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2016 06:12 AM
We are trying to compare two date to execute some function. However,the date time compare logic is off depends on the time of execution.
We would like to either zero out the time field or split the var into date only the split function doesn't seem to be functional
We have the following script
dateSection = dateSection.split(' ')[0]; //Gets the Date
var dateSection2 = new GlideDateTime();
dateSection2.addDaysUTC(-1*schd.frequency); //subtract frequency
dateSection2 = dateSection2.split(' ')[0]; //Gets the Date
var dateSectionComp = dateSection.compareTo(dateSection2);
var comp = last_run.compareTo(mark_date);
gs.log('Last run DateSection : ' + dateSection + ' DateSection2 Date : ' + dateSection2 + ' The comparison is : ' + dateSectionComp);
gs.log('Last run : ' + last_run + ' Mark Date : ' + mark_date + ' The comparison is : ' + comp);
The result should be the following
e,g
it should look like
from: 05/26/2016 12:34:56
and become the below
eg. 05/26/2016 00:00:00 or 05/26/2016
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2016 06:44 AM
Chuck,
Thanks for the reply. We tried but it doesn't seem to allow us to convert datetime to date with glidedate

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2016 06:56 AM
As chuck mentioned you can get date using GlideDate() API. Here is the sample code
var gd= new GlideDate();
gd.setDisplayValue(gs.nowDateTime());
gs.print(gd.getDisplayValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2016 06:49 AM
Hi Carlos,
I was struggling with this issue too. I got to this solution:
var datefieldDate = datefield.toString().slice(0,10);
which results in this date representation: 2016-08-02
or
var datefieldDate = datefield.getDisplayValue().toString().slice(0,10);
which results in this date representation: 02-08-2016
Regards,
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2017 02:06 PM
This is what I used and it worked in my scoped app:
var start_dates = new GlideDate();
start_dates = gs.quartersAgoStart(1);
var end_dates = new GlideDate();
end_dates = gs.quartersAgoEnd(1);
var real_start_date = start_dates.split(' ')[0];
var real_end_date = end_dates.split(' ')[0];
Then I returned the values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 09:51 PM
Hi @carlosrlara
you can try this ...........
var gdt = new GlideDateTime("2015-06-20 04:00:00");
var date=gdt.getDate();
gs.print(date);