Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date question...

Status
Not open for further replies.

aperfectcircle

Programmer
Apr 3, 2001
290
US
I can't really think of a good way to explain this so here's my best shot...

Ok...I can compare dates in javascript using > or < when I use Date()...for example:
Code:
var expiredate = new Date()
expiredate.setTime(expiredate.getTime() + (-90 * 24 * 3600 * 1000))
alert(&quot;Expire Date is &quot;+expiredate)

var today = new Date()
alert(&quot;Current Date is &quot;+today)

if (expiredate <= today) {
alert(&quot;Expire Date is less than Current Date&quot;)
}
if (expiredate >= today) {
alert(&quot;Expire Date is greater than Current Date&quot;)
}
The problem is that I want to compare a date that is stored in a database to the current date, but it won't work because the variable I get from the database is a string. In other words... is there a way to convert a string (already formatted like a date) to a date?

Thanks
 
Try using a script language such as php to convert time into timestamps that way u can compare the 2. Else u have to convert the string from the database to a date and compare that. MiQ
mick@nederland.net
wezine.vandermostvanspijk.nl
currently installed: html, JavaScript, dhtml, css, php, mysql, postgresql, xml, linux, apache
about to install: java, c++
 
Thanks for the reply...
The problem with the php idea is that I'm working off an AS/400... So even if a php build is available for it I doubt I'd be able to install it.

You said, &quot;Else u have to convert the string from the database to a date and compare that.&quot;
Any ideas on how to do that?

Also, I can put the info into the database in any format I want, I just used this way because I knew the logic to add or subtract days...

 
Ok, nevermind...I got it to work. I just set the values for the month, day, and year seperately in the database and then used Date(year,month,day) to set it as a date...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top