Convert String to Date

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 07:07 AM
Im so sorry but I have been searching for hours now so i need help.
How do you convert YYYY/MM/DD string into a date with YYYY-MM-DD format?
2 REPLIES 2

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 07:37 AM
Hello @Richard Tamparo
If you have value in string type variable, then you can simply replace / with - as below:
var oldFormat = '2014/10/22';
var newFormat = st.replace(/\//g, "-");
Thanks,
Ali
If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!
Thank you,
Ali
Thank you,
Ali
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 08:13 AM
You can pass date in string format in below code and get date
var search = '/';
var replaceWith = '-';
var dateStr='2023/06/15';
var result = dateStr.replaceAll(search, replaceWith);
var gdt= new GlideDateTime(result);
var date= gdt.getDate();
gs.print(date);