A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: date to number

  1. #1
    Member
    Join Date
    Sep 2014
    Posts
    77

    date to number

    hello all,

    in Excel, Dates can be formatted/converted to a single number. Is there a way in AS2.0 to do that?

    thanks,

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Umm, you just make a Date object and then use the getTime() function which "Returns the number of milliseconds since midnight January 1, 1970, universal time, for the specified Date object."

    Try this code:

    Code:
    var date:Date = new Date(2015, 03, 03, 10, 20, 30, 400);
    trace(date.getTime());
    where Date(year, month, date, hour, min, sec, ms)

    Hope this helps
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Member
    Join Date
    Sep 2014
    Posts
    77
    Thank you Sir for your help on that.
    - The first issue with that method; -ve numbers are obtained for dates before 1970 (<1970).
    - One more issue, now, if that same resulted number is needed to be converted back to the same date?
    The reason for asking this, to plot data on chart like in excel e.g. (Date vs. any-variable) .

    Regards!

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    Perhaps this might get you further along.

    PHP Code:
    var dateToGet:Date = new Date(1969111020);
    trace("Date: " dateToGet);

    var 
    dateToGetNumber:Number dateToGet.getTime();
    trace("Date number: " dateToGetNumber);

    var 
    numberToDate:Date = new Date(dateToGetNumber);
    trace(dateToGetNumber " -> " numberToDate); 
    and you might or probably do need to offset it.

    PHP Code:
    var utcOffset numberToDate.getTimezoneOffset() * 60 1000;
    var 
    utcNow:Date = new Date(numberToDate.valueOf() + utcOffset);
    trace(utcNow); 

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi again,

    This might help too.

    PHP Code:
    var numbers:Array = new Array(128946000000468930000000770808000000);
    var 
    dates:Array = new Array();

    for (var 
    i:Number 0numbers.lengthi++)
    {
        var 
    numberToDate:Date = new Date(numbers[i]);
        var 
    offset:Number convert.getTimezoneOffset() * 60 1000;
        var 
    convertDate:Date = new Date(numberToDate.valueOf() + offset);
        
    trace(": " numbers[i] + " -> " numberToDate);
        
    dates.push(numberToDate);
    }


    for (var 
    j:Number 0dates.lengthj++)
    {
        var 
    dateToNumber:Number dates[j].getTime();
        
    trace("Date to number: " dates[j] + " -> " dateToNumber);


  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    slight error there, ->
    PHP Code:
    var numbers:Array = new Array(128946000000468930000000770808000000);
    var 
    dates:Array = new Array();

    for (var 
    i:Number 0numbers.lengthi++)
    {
        var 
    numberToDate:Date = new Date(numbers[i]);
        var 
    offset:Number numberToDate.getTimezoneOffset() * 60 1000;
        var 
    convertDate:Date = new Date(numberToDate.valueOf() + offset);
        
    trace("Number to date: " numbers[i] + " -> " convertDate);
        
    dates.push(convertDate);
    }


    for (var 
    j:Number 0dates.lengthj++)
    {
        var 
    dateToNumber:Number dates[j].getTime();
        
    trace("Date to number: " dates[j] + " -> " dateToNumber);

    but i'm sure you can get to grips with it

  7. #7
    Member
    Join Date
    Sep 2014
    Posts
    77
    Quote Originally Posted by fruitbeard View Post
    Hi again,

    This might help too.

    PHP Code:
    var numbers:Array = new Array(128946000000468930000000770808000000);
    var 
    dates:Array = new Array();

    for (var 
    i:Number 0numbers.lengthi++)
    {
        var 
    numberToDate:Date = new Date(numbers[i]);
        var 
    offset:Number convert.getTimezoneOffset() * 60 1000;
        var 
    convertDate:Date = new Date(numberToDate.valueOf() + offset);
        
    trace(": " numbers[i] + " -> " numberToDate);
        
    dates.push(numberToDate);
    }


    for (var 
    j:Number 0dates.lengthj++)
    {
        var 
    dateToNumber:Number dates[j].getTime();
        
    trace("Date to number: " dates[j] + " -> " dateToNumber);


    Thank you fruitbeard,

    This code works great.

    Regards!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center