- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2020 10:24 PM
Hi,
I need to change the date format to 'yyyy-mm-dd' of a date type field even if user enters date manually.
I tried with getByFormat but it is returning wrong year. Kindly help.
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2020 11:36 PM
Hi,
Please use MM instead of mm, and it will work.
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2020 11:00 PM
Thanks Asif, This is working fine for 'MM-dd-yyyy' format. But when i tried the same for 'yyyy-mm-dd'. It is not working. Returning 00 for month.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2020 11:06 PM
Hello aamir,
Can you share your current date format in which you are getting and the script you are trying. We need to first convert that to 1 format as input and then convert to our required format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2020 11:25 PM
Hi Asif,
Below is my code-
onchange client script
=============
var ga = new GlideAjax('scriptinclude');
ga.addParam("sysparm_name", "methodname");
ga.addParam("sysparm_sdate", newValue);
script include
==============
var str = this.getParameter('sysparm_sdate');
var todayDateTime = new GlideDateTime(str);
var dateE= todayDateTime.getLocalDate().getByFormat('yyyy-mm-dd');
gs.log("dateE"+dateE);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2020 11:36 PM
Hi,
Please use MM instead of mm, and it will work.
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP