- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2018 08:52 AM
How to get today's date in MM-DD-YYYY format without time in script?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2018 10:10 AM
var currentdate = new GlideDate();
currentdate.getByFormat("MM-dd-yyyy");

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2020 09:34 AM
result came back as: 2020-02-19 or yyyy-mm-dd

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2018 11:39 AM
IF you want in business rule, then use below code to get current time without time
Set date via business rule action
IF you want in client script, then use below code to get current date without time
https://community.servicenow.com/community?id=community_question&sys_id=38c40be9dbd8dbc01dcaf3231f9619e3
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2018 10:10 AM
var currentdate = new GlideDate();
currentdate.getByFormat("MM-dd-yyyy");

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2019 09:14 PM
Hi Hars,
I have used your code, its working but, I want to change my date format to "dd-MM-yyyy". when I changed your code as below its now working.
var currentdate = new GlideDate();
currentdate.getByFormat(''dd-MM-yyyy");
I am getting 09-10-2021. My current system date is 19-06-2019. Can you plz suggest.
Regards,
Sandeep Reddy Lebaka.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2024 12:58 AM
Sure, you can use the following JavaScript code in ServiceNow to get today's date in MM-DD-YYYY format without time:
javascript
var gdt = new GlideDateTime();
var date = gdt.getLocalDate();
var formattedDate = date.getMonth() + '-' + date.getDay() + '-' + date.getYear();
gs.info(formattedDate);
Here are the steps:
- Create a new GlideDateTime object.
- Use the getLocalDate() method to get the current date.
- Use the getMonth(), getDay(), and getYear() methods to get the month, day, and year respectively.
- Concatenate these values with '-' to get the date in MM-DD-YYYY format.
- Use the gs.info() method to log the formatted date.
nowKB.com