I am using UTC() to get the number of millisecs since Jan 1,1970 for “today”, subtracting 604800 (60*60*24*7) and using this new value (calculated as a var,lastweek) in new Date(lastweek) in order to get the date a week ago. The result I get is today’s values for the date, not those for a week ago. Please, what am I doing wrong? How can I get the date a week ago?
@ExuroJan 10.2005 — #[i]Originally posted by Krumbly [/i]
[B]I am using UTC() to get the number of millisecs since Jan 1,1970 for "today", subtracting 604800 (60*60*24*7)[/B][/QUOTE]
The value [FONT=courier new]60*60*24*7[/FONT] would be the number of [i]seconds[/i] in a week, not miliseconds. You need to add a [FONT=courier new]1000*[/FONT] to the front:
<script type="text/javascript"> <!-- var today = new Date(); var lastWeek = new Date(today.getTime()-[color=red]1000*[/color]60*60*24*7); alert("Today: " + today + "nLast Week: " + lastWeek); //--> </script>
@ExuroJan 10.2005 — #I don't understand what that has to do with error handling... Would you mind explaining?
[b]Unrelated Sidenote to Charles:[/b]
I believe the title you're looking for is [i]senpai[/i] rather than [i]sempai[/i]. I don't know why it happens, but I've heard several Japanese words that get the "n" switched for an "m". For example, "numchucks" are actually "nunchucks" from the Japanese word [i]nunchaku[/i].
Just out of curiosity, are you saying you're a [i]senpai[/i] here at the forums, being one older and more experienced and lending help to those less experienced? Or does it actually have something to do with the samurai/kendo picture you have as your avatar?
@CharlesJan 10.2005 — #With the JavaScript Date object, the incorrect date "-2 January 2005" becomes 29 December 2004.
"Sempai" is how my school transliterates the word. 20 people are more senior than I on this board and only four have more posts. I needed a word that went better with my Avatar, which I picked largely because of the colors. "Sempai" seemed apt, somehow.
@KrumblyauthorJan 10.2005 — #Thanks Exuro. I wish I could claim the missing multiplier (sec to millisecs) was a deliberate error, but it was just a stupid oversight.
And thanks Charles, your:
then = new Date();
then.setDate (then.getDate() - 7);
alert (then.toDateString());
is what I wanted but couldn't get to work (I'm checking that a date entered, in a form, is at least a week ago).
@ExuroJan 10.2005 — #[i]Originally posted by Charles [/i]
[B]With the JavaScript Date object, the incorrect date "-2 January 2005" becomes 29 December 2004.[/B][/QUOTE] Ah, that makes sense. I love it when scripts do that! It makes coding so much easier when the dates will auto-correct themselves. Blackbox all the way!
[i]Originally posted by Charles [/i]
[B]"Sempai" seemed apt, somehow. [/B][/QUOTE] Fine then, spurn my four years of Japanese :p