This is a discussion on "compairing dates like 08/29/2007 to 08/30/2007" within the JavaScript Forum section. This forum, and the thread "compairing dates like 08/29/2007 to 08/30/2007 are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
compairing dates like 08/29/2007 to 08/30/2007
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
compairing dates like 08/29/2007 to 08/30/2007
is there a way to compare dates/times using javascript that are already coded to output like this: 08/29/2007 08:30 to 08/30/2007 10:00
Var CurrentDateTime output: "MM/DD/YYYY HH:MM" I am trying to find a way to calculate if the deadline for a project has passed, and have been stuck on the if statement, since you cant really compare variables that have slashes, spaces, and colons in them... or can you? Any help would be appreciated. thx Last edited by selfAfflicted; Aug 29th, 2007 at 13:43. |
|
|
|
|||
|
Re: compairing dates like 08/29/2007 to 08/30/2007
Hello selfAfflicted
You probably want to convert the dates to epoch seconds.
Hope that helps Justin |
|
|||
|
Re: compairing dates like 08/29/2007 to 08/30/2007
Since I don't know how I would get "08/29/2007 9:30" into epoch seconds, I don't think I will be able to do this.
I have no control over the way the variable displays because its a built-in javascript function that I call on with a tag, kind of like cf does with some of its functions. I guess my original question was if you could do math with a variable that output like this "08/29/2007 9:30" I am going to go back to that. Is there a way, if I have no control over how the variable is populated if I can edit its contents. such as: If I have a variable named currentDateTime and its output is "MM/DD/YYYY HH:MM" is there a way to separate out its values like this: "MM" = currentMonth "DD" = currentDay "YYYY" = currentYear "HH" = currentHour "MM" = currentMinute. The reason I dont have control over the currentDateTime script is because its a built in function, that calls for the server time. Last edited by selfAfflicted; Aug 29th, 2007 at 15:00. |
|
||||
|
Re: compairing dates like 08/29/2007 to 08/30/2007
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
|||
|
Re: compairing dates like 08/29/2007 to 08/30/2007
I'm talking about extracting MM DD YYYY HH MM from the current date time variable - cause thats the variable that gets the servers time.
|
|
||||
|
Re: compairing dates like 08/29/2007 to 08/30/2007
But if you convert both strings back to Date objects then you can easily compare them.
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
|||
|
Re: compairing dates like 08/29/2007 to 08/30/2007
Hi SelfAfflicted
* [quote] Since I don't know how I would get |
|
|||
|
Re: compairing dates like 08/29/2007 to 08/30/2007
Quote:
[code] var projectTime = "08/29/2007 9:30"; var dateArray = projectTime.split(" "); //split on the space so dateArray[0] is the date part and //dateArray[1] is the time part. var dateArray2 = dateArray[0].split("/"); //split the date part into its parts //feed Date year, month , day //nb month starts Jan = 0 so you need to - 1 varProjectTimeObject = new Date(dateArray2[2] , (dateArray2[0]-1) , dateArray2[1]) varProjectTimeObjectEpoch = varProjectTimeObject.getTime(); //so varProjectTimeObjectEpoch now contains epoch seconds for this date. //to get epoch secs for now is easier: varNow = new Date(); varNow = varNow.getTime(); //now just compare varNow and varProjectTimeObjectEpoch [code] I think this is ok. Splitting on the space could be improved using a substring function perhaps. It isn't a big deal. You just need to use string functions to get your date string into the format required to create a date object to represent it. Split() is very useful Justin |
![]() |
| Tags |
| deadline, dates, date, compair |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| November 2007 - Repertoire-2007.co.uk | Daniel | Hall of Fame | 19 | Nov 3rd, 2007 22:23 |
| May 2007 - RegisteredSleepers.com | Daniel | Hall of Fame | 11 | Jun 26th, 2007 09:50 |
| Memorial Day 2007 | sannbe | Webforumz Cafe | 10 | May 28th, 2007 21:21 |
| WOTM - May 2007 | Daniel | Entry, Nominations and Voting | 14 | May 24th, 2007 08:35 |