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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with cookies, dates, and strings (together)

Status
Not open for further replies.

marct

Programmer
Apr 6, 1999
32
0
0
US
Hi,

I need to get a string from a cookie that is a date, add an hour to it, and put it back in the cookie. I seem to be having a problem getting the string in the cookie converted to a date so I can add an hour. VBScript has a CDate function that will do this, but I can't find an equivalent for javascript. Can anyone help?

Thanks in advance,

Marc Tower [sig][/sig]
 
Marc,

Try this...

Code:
<html>
<head>
<script language=&quot;javascript&quot;>
var strDate = &quot;Tue, 12 Sep 2000 14:44:00&quot;; //this would be the cookie date variable
intMSinHour = 3600000; //milliseconds in hour

document.write(&quot;Original String =&quot; + strDate + &quot;<br>&quot;);

intMSDate = Date.parse(strDate); //convert date to number of milliseconds since Jan 1, 1970

intTotal = intMSinHour + intMSDate; 

objNewDate = new Date(intTotal);
var strNewDate = objNewDate.toString();

document.write(&quot;New String =&quot; + strNewDate);
</script>
</head>
</html>

You will, of course, have to format the date/time to make it the same on the in and the out but the script does indeed add an hour.

Rob [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top