[thelist] JS: Date.UTC woes

Frank lists at frankmarion.com
Fri Jun 22 18:22:18 CDT 2007

Hi all,

I've function that's intended to count a span of time as X years, Y 
months, Z weeks and Q days. In short, I'm basically "subtracting" a 
past date from Now.

I must pass my params as such:

var now = Date.UTC(2007,5,22,0,0,0);  // today
var then = Date.UTC(1967,6,24,0,0,0); // a past date

function TimeSpan(now,then) {
    // stuff

This works fine, but I can't get the Now to be dynamic. Whipped up a 
quick little function to generate the necessary string 
(YYYY,MM,dd,0,0,0) that correctly returns "2007,5,22,0,0,0"

function UTCFormatNow() {
         Now = new Date();
         Year = calcYear(Now); // figures out the correct year in 4 
digit format 'YYYY'
         Month = Now.getMonth();
         DoM = Now.getDate();
         strFormatted = Year + ',' + Month + ',' + DoM + ',0,0,0'
         strFormatted =  strFormatted.toString(); // <-- redundant?
         return strFormatted;

yet when I try to do Date.UTC(UTCFormatNow()), I get NaN.

It seems that I can't use any function or method it Date.UTC();

Can someone suggest how I can get the correct DateUTC for NOW, or how 
to correctly insert the arguments needed?

Many thanks.

Frank Marion     lists at frankmarion.com      Keep the signal high.

More information about the thelist mailing list