Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
if (reportDate >= payStartDate && reportDate <= payEndDate)

reporteddate is in the format of "mm/dd/yyyy" and startdate and enddate are in the format of
Sat Dec 14 00:00:00 EST 2013 . Because of this I couldn't compare both dates. Can I please know how to compare these 2 different date formats?
Posted
Updated 4-May-14 6:51am
v3
Comments
[no name] 4-May-14 12:51pm    
You are going to need to parse the datetime variable to a common format.
Kornfeld Eliyahu Peter 4-May-14 12:59pm    
reportDate, payStartDate and payEndDate are Date objects or strings?
Member 10793987 4-May-14 13:04pm    
date objects

As all your variables are already Date object you can simply compare them. The original format of the string from which the Date object was created does not matter anymore...
 
Share this answer
 
There is no in-built date conversion format in JavaScript, but you can use Moment.js (a third-party) library. It's quite flexible.

http://momentjs.com/[^]
 
Share this answer
 
v3
You can parse date strings in JavaScript using the inbuilt Date object.

You can easily find date parsing JavaScript functions with a little googling. However I am saving your time by giving you the following code:

C#
//returns meaningful date format
function getDate(rawDate) {
    rawDate = new Date(Date.parse(rawDate));
    var month = rawDate.getMonth(),
        day = rawDate.getDate(),
        year = rawDate.getFullYear();
    return month + "/" + day + "/" + year;
}
console.log(getDate('Sat Dec 14 00:00:00 EST 2013'));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900