The best string format for string parsing is the date ISO format together with the JavaScript Date object constructor.

Examples of ISO format: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS.

But wait! Just using the "ISO format" doesn't work reliably by itself. String are sometimes parsed as UTC and sometimes as localtime (based on browser vendor and version). The best practice should always be to store dates as UTC and make computations as UTC.

To parse a date as UTC, append a Z - e.g.: new Date('2011-04-11T10:20:30Z').

To display a date in UTC, use .toUTCString(),
to display a date in user's local time, use .toString().

More info on MDN | Date and this answer.

For old Internet Explorer compatibility (IE versions less than 9 do not support ISO format in Date constructor), you should split datetime string representation to it's parts and then you can use constructor using datetime parts, e.g.: new Date('2011', '04' - 1, '11', '11', '51', '00'). Note that the number of the month must be 1 less.


Alternate method - use an appropriate library:

You can also take advantage of the library Moment.js that allows parsing date with the specified time zone.

Answer from Pavel Hodek on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › parse
Date.parse() - JavaScript | MDN
// Standard date-time string format const unixTimeZero = Date.parse("1970-01-01T00:00:00Z"); // Non-standard format resembling toUTCString() const javaScriptRelease = Date.parse("04 Dec 1995 00:12:00 GMT"); console.log(unixTimeZero); // Expected output: 0 console.log(javaScriptRelease); // Expected output: 818035920000
🌐
Scaler
scaler.com › home › topics › convert string to date in javascript
Convert String to Date in JavaScript - Scaler Topics
January 10, 2024 - There is a class in JavaScript called the Date class. You can use this function to get the current date and time of the local system. You can also use this class's constructor to convert a date value from string data type to Date data type.
Discussions

Parsing a string to a date in JavaScript - Stack Overflow
How can I convert a string to a Date object in JavaScript? var st = "date in some format" var dt = new Date(); var dt_st = // st in Date format, same as dt. More on stackoverflow.com
🌐 stackoverflow.com
Convert string to date in javascript
For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you · On my apex page I have a hidden item P1_STORE_DT which stores date in '01-AUG-13' format More on forums.oracle.com
🌐 forums.oracle.com
July 29, 2013
JavaScript: how to convert a string to a formatted date?
You can check out the JavaScript Date object. You can create a Date object multiple ways, including passing in the exact string in your question: new Date('1977-04-22');. From there, the Date object has a few built in formatting functions like date.toDateString() which outputs Fri Apr 22 1977. (Be careful though. At the moment, for me it outputs 'Thu Apr 21 1977' since creating the date object with a string defaults to UTC time but the output is in my local timezone). https://css-tricks.com/everything-you-need-to-know-about-date-in-javascript/ and other Google results give more details about how to use the Date object. More on reddit.com
🌐 r/learnprogramming
7
2
May 21, 2020
javascript - Get String in YYYYMMDD format from JS date object? - Stack Overflow
Still don't know why (perhaps the replacement string is just a place holder for a separator). The 'g' means all occurrences. The pattern you are thinking of is /[-]+/g 2016-12-21T17:40:17.78Z+00:00 ... Guillaume F. Guillaume F. Over a year ago · You made my day. I've been searching for days for a simple way to bypass the horrible TimeZone handling in Javascript... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Index.dev
index.dev › blog › convert-string-to-date-javascript
6 Simple Methods to Convert Strings to Dates in JavaScript
date in JavaScript, accompanied with distinct code samples and practical insights. A straightforward technique to convert a string to a date is by use the Date constructor.
🌐
W3Schools
w3schools.com › jsref › jsref_parse.asp
JavaScript Date parse() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST
Top answer
1 of 16
1087

The best string format for string parsing is the date ISO format together with the JavaScript Date object constructor.

Examples of ISO format: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS.

But wait! Just using the "ISO format" doesn't work reliably by itself. String are sometimes parsed as UTC and sometimes as localtime (based on browser vendor and version). The best practice should always be to store dates as UTC and make computations as UTC.

To parse a date as UTC, append a Z - e.g.: new Date('2011-04-11T10:20:30Z').

To display a date in UTC, use .toUTCString(),
to display a date in user's local time, use .toString().

More info on MDN | Date and this answer.

For old Internet Explorer compatibility (IE versions less than 9 do not support ISO format in Date constructor), you should split datetime string representation to it's parts and then you can use constructor using datetime parts, e.g.: new Date('2011', '04' - 1, '11', '11', '51', '00'). Note that the number of the month must be 1 less.


Alternate method - use an appropriate library:

You can also take advantage of the library Moment.js that allows parsing date with the specified time zone.

2 of 16
452

Unfortunately I found out that

var mydate = new Date('2014-04-03');
console.log(mydate.toDateString());

returns "Wed Apr 02 2014". I know it sounds crazy, but it happens for some users.

The bulletproof solution is the following:

var parts ='2014-04-03'.split('-');
// Please pay attention to the month (parts[1]); JavaScript counts months from 0:
// January - 0, February - 1, etc.
var mydate = new Date(parts[0], parts[1] - 1, parts[2]); 
console.log(mydate.toDateString());

🌐
Swovo
swovo.com › blog › convert-string-to-date-javascript
Convert String to Date JavaScript - Swovo
The Date.parse() method in JavaScript converts a date string into a date object’s timestamp. Using a library like Moment.js can provide more flexibility and handle various date formats.
🌐
Turing
turing.com › kb › converting-string-to-date-in-js
Learn the Basics of Converting String to Date in JavaScript
There are five different ways to change a date value from a string data type to a date type. By using the Date() function in JavaScript. By using parse(), UTC() which are static methods of the Date construct.
Find elsewhere
🌐
W3Schools
w3schools.com › jsref › jsref_tostring_date.asp
JavaScript Date toString() Method
❮ Previous JavaScript Date Reference Next ❯ · Convert a date object to a string: const d = new Date(); let text = d.toString(); Try it Yourself » · The toString() method returns a date object as a string.
🌐
TutorialsTeacher
tutorialsteacher.com › javascript › javascript-date
JavaScript Date: Create, Convert, Compare Dates in JavaScript
The following example converts a date string to DD-MM-YYYY format. ... var date = new Date('4-1-2015'); // M-D-YYYY var d = date.getDate(); var m = date.getMonth() + 1; var y = date.getFullYear(); var dateString = (d &lt;= 9 ? '0' + d : d) + '-' + (m <= 9 ? '0' + m : m) + '-' + y; ... Use third party JavaScript Date library like datejs.com or momentjs.com to work with Dates extensively in JavaScript.
🌐
W3Schools
w3schools.com › js › js_date_formats.asp
JavaScript Date Formats
Independent of input format, JavaScript will (by default) output dates in full text string format: ISO 8601 is the international standard for the representation of dates and times. The ISO 8601 syntax (YYYY-MM-DD) is also the preferred JavaScript date format: const d = new Date("2015-03-25"); Try it Yourself » · The computed date will be relative to your time zone.
🌐
Chris Pietschmann
pietschsoft.com › post › 2023 › 09 › 28 › javascript-parse-string-to-a-date
JavaScript: Parse a String to a Date | Chris Pietschmann
September 28, 2023 - Then, you can parse the date string using Moment.js and specify the desired time zone: var st = "2023-09-28T14:30:00"; var dt_st = moment(st).utc(); // Parse as UTC · Moment.js offers a wide range of formatting and manipulation options, making it a powerful tool for working with dates and times in JavaScript.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › convert-string-into-date-using-javascript
Convert string into date using JavaScript - GeeksforGeeks
July 11, 2025 - The JavaScript Date parse() Method is used to know the exact number of milliseconds that have passed since midnight, January 1, 1970, till the date we provide. ... Example: In this example, we will use date.parse() method to get time out of ...
🌐
Oracle
forums.oracle.com › ords › apexds › post › convert-string-to-date-in-javascript-0266
Convert string to date in javascript
July 29, 2013 - Hi,On my apex page I have a hidden item P1_STORE_DT which stores date in '01-AUG-13' format.Now what i need to do is convert this into date in javascriptOn page load i execute below codevar d=new Date...
🌐
Reddit
reddit.com › r/learnprogramming › javascript: how to convert a string to a formatted date?
r/learnprogramming on Reddit: JavaScript: how to convert a string to a formatted date?
May 21, 2020 -

This has got me stumped. I've read dozens of StackOverflow posts about similar things but I cannot get it working.

I have a string like 1977-04-22. I want to change this to a different kind of date format, eg 22nd April 1977.

I am really not sure how to go about this and am very confused.

Would anyone be able to help me or point me in the right direction?

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
For example, "2011-10-10" (date-only form), "2011-10-10T14:48:00" (date-time form), or "2011-10-10T14:48:00.000+09:00" (date-time form with milliseconds and time zone) are all valid date time strings. When the time zone offset is absent, date-only forms are interpreted as a UTC time and date-time forms are interpreted as a local time. The interpretation as a UTC time is due to a historical spec error that was not consistent with ISO 8601 but could not be changed due to web compatibility.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toString
Date.prototype.toString() - JavaScript | MDN
July 10, 2025 - const event = new Date("August 19, 1975 23:15:30"); console.log(event.toString()); // Expected output: "Tue Aug 19 1975 23:15:30 GMT+0200 (CEST)" // Note: your timezone may vary ... A string representing the given date (see description for the format).
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toDateString
Date.prototype.toDateString() - JavaScript | MDN
const event = new Date(1993, 6, 28, 14, 39, 7); console.log(event.toString()); // Expected output: "Wed Jul 28 1993 14:39:07 GMT+0200 (CEST)" // Note: your timezone may vary console.log(event.toDateString()); // Expected output: "Wed Jul 28 1993" ... A string representing the date portion of the given date (see description for the format).
Top answer
1 of 2
2
You need to change that string into a date before you evaluate it in the loop. What is the format of the current string? Inside your for loop do something like this.Option 1 - using vanilla JS (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)const myDate = Date.parse(new Date(result.@mailDate));//thenIf(myDate > date2){} Option 2 - using ACC Date functionconst myDate = formatDate(result.@mailDate, "%4Y/%2M/%2D")//thenIf(myDate > date2){}https://experienceleague.adobe.com/developer/campaign-api/api/f-formatDate.html  Option 3 - using moment JS (be aware library still works although it is not being investing in anymore, but it still makes it easier). This helped me when I was doing advanced date manipulation 100+ lines of JS.https://blog.floriancourgey.com/2018/10/use-javascript-libraries-in-adobe-campaign/  I've done all 3. Which ever fits your context the best is the right one to use.
2 of 2
3
Hello,I don't know if that help, but there is some documentation about using dates in Campaign:https://experienceleague.adobe.com/developer/campaign-api/api/p-5.htmlThe example says var query = NLWS.xtkQueryDef.create( {queryDef: {schema: "nms:delivery", operation: "get", select: { node: {expr: "@lastModified"} }, where: { condition: {expr: "@id=123456"} } }})var delivery = query.ExecuteQuery()var lastModified = parseTimeStamp(delivery.$lastModified) // <-- parseTimeStamp returns a Date objecthttps://experienceleague.adobe.com/developer/campaign-api/api/f-parseTimeStamp.html?hl=parsetimestamp  Best regards, Tobias
🌐
Day.js
day.js.org › docs › en › display › format
Format · Day.js
dayjs().format() // current date in ISO8601, without fraction seconds e.g. '2020-04-02T08:02:17-05:00' dayjs('2019-01-25').format('[YYYYescape] YYYY-MM-DDTHH:mm:ssZ[Z]') // 'YYYYescape 2019-01-25T00:00:00-02:00Z' dayjs('2019-01-25').format('DD/MM/YYYY') // '25/01/2019' More available formats Q Do k kk X x ... in plugin AdvancedFormat · Because preferred formatting differs based on locale, there are a few localized format tokens that can be used based on its locale.