Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

String date to date conversion

Rushi2
Tera Expert

I want to convert string date (2019-MAR-22)  to date format (03-22-2019). 

Regards, 

Rushi

1 ACCEPTED SOLUTION

Chander Bhusha1
Tera Guru

Hi Rushi,

Try the below script:

 

Script: 

var date = '2019-MAR-22';//Input Date

var gd = new GlideDate();
gd.setDisplayValue(date, "yyyy-MMM-dd");


gs.print('output   '+gd.getByFormat("MM/dd/yyyy"));//Output

 

 

Output of the srcript would be :

 

find_real_file.png

 

 

Please mark helpful and correct.

 

Thanks,

CB

View solution in original post

7 REPLIES 7

Namrata Khabale
Giga Guru

Hey Rushi,

Here is a same thread you are looking for, it might help you:

 

https://community.servicenow.com/community?id=community_question&sys_id=23cc1ad6db8753082be0a851ca96...

 

Mark correct and helpful if you find response Worthy!!


Best Regards,

Namrata.

MrMuhammad
Giga Sage

Try this.

var date = '2019-Mar-22';

var gdt = new GlideDateTime(date);
gdt.getDate();

Regards,
Muhammad

Anil Shewale
Mega Guru

Hi Rushi

 

Try following script:

var date = '10 Jul 2018 12:30:00';
var simpleDateFormat = 'dd MMMM yyyy HH:mm:ss'; // Simple Date Time format
var gdt = new GlideDateTime();

gdt.setDisplayValue(date,simpleDateFormat); //Set time using current TZ
gs.addInfoMessage(gdt.getDisplayValue()); // Output time in current TZ
2018-07-10 12:30:00 PM

 

If it help mark helpful or correct 

Thanks and regards

Anil

Chander Bhusha1
Tera Guru

Hi Rushi,

Try the below script:

 

Script: 

var date = '2019-MAR-22';//Input Date

var gd = new GlideDate();
gd.setDisplayValue(date, "yyyy-MMM-dd");


gs.print('output   '+gd.getByFormat("MM/dd/yyyy"));//Output

 

 

Output of the srcript would be :

 

find_real_file.png

 

 

Please mark helpful and correct.

 

Thanks,

CB