How to convert Date/Time into timestamp format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 08:29 AM
Hi all,
How to convert Datetime format into timstamp format
gs.info(new GlideDateTime(new GlideDateTime().getDsiplayValue());
2024-04-16 11:45:23
kindly help me how to convert into timestamp format expecting result into timestamp format 20240416114523

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 08:54 AM - edited 04-16-2024 08:55 AM
I don't see anything that will convert it into that format so you will have to do some coding. I think something like this should work.
var dateTime = new GlideDateTime().getDisplayValue().toString();
var dateTimeSplit = dateTime.split(' '); // Seperate date time into two strings date and time.
var timeStamp = dateTimeSplit[0].replaceAll("-", "") + dateTimeSplit[1].replaceAll(":", ""); //Use replace all to remove unneeded characters and recombine the string.
gs.info(timeStamp);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 10:28 AM
Yes, it's working good, returning result in Timestamp format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 09:05 AM
Hi @Supriya25,
Try this scripts -
gs.info(new GlideDateTime().getDisplayValue());
// 20240416114523
var date = new GlideDateTime();
var time_stamp = date.toString().replace('-', '').toString().replace(' ', '').toString().replace(':', '');
gs.info(time_stamp);
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 10:29 AM
Tq, Yes, it's working good, returning result in Timestamp format