compairing dates like 08/29/2007 to 08/30/2007

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.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 29th, 2007, 13:29
New Member
Join Date: Aug 2007
Location: San Antonio, TX
Age: 21
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Reply With Quote

  #2 (permalink)  
Old Aug 29th, 2007, 14:18
Up'n'Coming Member
Join Date: Aug 2007
Location: Bicester
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Re: compairing dates like 08/29/2007 to 08/30/2007

Hello selfAfflicted

You probably want to convert the dates to epoch seconds.

Code: Select all
 
var projectDate = new Date() // set up the date here based on the strings you have (you need to look up the Date constructor)
projectDateSecs = projectDate.getTime()//secs since base time
You may need to do some string parsing to create the date object properly. The basic idea is to put the date into epoch seconds then you can do a numerical comparison

Hope that helps

Justin
Reply With Quote
  #3 (permalink)  
Old Aug 29th, 2007, 14:33
New Member
Join Date: Aug 2007
Location: San Antonio, TX
Age: 21
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Reply With Quote
  #4 (permalink)  
Old Aug 29th, 2007, 15:31
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
Re: compairing dates like 08/29/2007 to 08/30/2007

http://www.comptechdoc.org/independe.../javadate.html
Reply With Quote
  #5 (permalink)  
Old Aug 29th, 2007, 15:37
New Member
Join Date: Aug 2007
Location: San Antonio, TX
Age: 21
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Reply With Quote
  #6 (permalink)  
Old Aug 29th, 2007, 15:53
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
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.
Reply With Quote
  #7 (permalink)  
Old Aug 29th, 2007, 16:07
Up'n'Coming Member
Join Date: Aug 2007
Location: Bicester
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Re: compairing dates like 08/29/2007 to 08/30/2007

Hi SelfAfflicted
*
[quote]

Since I don't know how I would get
Reply With Quote
  #8 (permalink)  
Old Aug 29th, 2007, 16:09
Up'n'Coming Member
Join Date: Aug 2007
Location: Bicester
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Re: compairing dates like 08/29/2007 to 08/30/2007

Quote:
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.

[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
Reply With Quote
  #9 (permalink)  
Old Aug 29th, 2007, 16:23
New Member
Join Date: Aug 2007
Location: San Antonio, TX
Age: 21
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Re: compairing dates like 08/29/2007 to 08/30/2007

thanks, we'll see how far I get with this in a while!
Reply With Quote
Reply

Tags
deadline, dates, date, compair

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 10:42.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43