Graphics

 View Only
Expand all | Collapse all

Timestamp conversion

  • 1.  Timestamp conversion

    Posted 03-06-2012 15:33
    I have a timestamp field in my Newsticker datalinq feed. Currently it is formatted as '2012-3-6 12:55:53'. I asked Newsticker to reformat it as 'March 6, 2012 12:53' on their end, but they suggested I talk with Ross about reformatting it inside of the scene..

    Any thoughts?


  • 2.  RE: Timestamp conversion

    Posted 03-06-2012 16:06
    Clarification:

    It's a standard (24-hr based) SQL timestamp:

    YYYY-MM-DD HH:MM:SS

    2012-03-06 14:52:06

    #XPression


  • 3.  RE: Timestamp conversion

    Posted 03-06-2012 17:54
    Adam,

    Typically this would be done as a scripted piece that is attached the the text object. This give you control over the format requirements.

    If you need help with it please let us know and we can post some ideas for you.

    -g

    #XPression


  • 4.  RE: Timestamp conversion

    Posted 03-06-2012 18:14
    Glen,

    That would be great, my scripting knowledge is fairly barebones...

    #XPression


  • 5.  RE: Timestamp conversion

    Posted 03-06-2012 19:22
    Adam,

    Place the following script into the "OnSetText" script event of the text object that holds the timestamp. This script will replace the timestamp with the newly formatted text. Since the OnSetText event only gets run when the scene is put online from the sequencer, you won't see the effects if you are just double clicking the scene to put it online from layout mode.



    dim timestamp as date

    timestamp = text

    text = MonthName(Month(timestamp)) & " " & Day(timestamp) & ", " & Year(timestamp) & " " & Hour(timestamp) & ":" & Minute(timestamp)



    #XPression


  • 6.  RE: Timestamp conversion

    Posted 03-06-2012 21:51
    Thanks Brian, this works great. Is there any way to convert the the 24hr clock to a 12 hour am/pm format?

    #XPression


  • 7.  RE: Timestamp conversion

    Posted 03-07-2012 04:05
    Sure.. I'm sure this could be optimized a lot; but here is an example:



    dim timestamp as date

    dim hr as integer

    timestamp = text

    hr = Hour(timestamp)

    ' Add the Month Day, Year

    text = MonthName(Month(timestamp)) & " " & Day(timestamp) & ", " & Year(timestamp) & " "

    ' Add the hours (subtracting 12 from anything over 12

    if (hr > 12) then

    text = text & (hr - 12)

    else

    text = text & (hr)

    end if

    text = text & ":" & Minute(timestamp)

    ' Make sure that 00 shows as AM and 12 shows as PM

    if (hr >= 12) then

    text = text & "pm"

    else

    text = text & "am"

    end if



    #XPression


  • 8.  RE: Timestamp conversion

    Posted 03-07-2012 15:13
    This is great! I really appreciate your help. The script make sense once I see it, but I struggle with the initial language and syntax. Thanks again...

    #XPression


  • 9.  RE: Timestamp conversion

    Posted 03-08-2012 17:11
    One follow up question: It seems that if the minutes begin with a '0' (12:00-12:09, etc.) it drops the zero and only displays the second digit. The current read out reads "12:5pm". it does this thoughout the day, no matter the hour.

    Any thoughts?

    #XPression


  • 10.  RE: Timestamp conversion

    Posted 03-08-2012 17:18
    Didn't notice that.. Sorry..

    Try this: (got this idea from here: VBScript dates)



    dim timestamp as date

    dim hr as integer

    timestamp = text

    hr = Hour(timestamp)

    ' Add the Month Day, Year

    text = MonthName(Month(timestamp)) & " " & Day(timestamp) & ", " & Year(timestamp) & " "

    ' Add the hours (subtracting 12 from anything over 12

    if (hr > 12) then

    text = text & (hr - 12)

    else

    text = text & (hr)

    end if

    text = text & ":" & Right("0" & Minute(timestamp), 2)

    ' Make sure that 00 shows as AM and 12 shows as PM

    if (hr >= 12) then

    text = text & "pm"

    else

    text = text & "am"

    end if



    #XPression


  • 11.  RE: Timestamp conversion

    Posted 03-08-2012 22:29
    Perfect! I even expanded the script to replace the timestamp with custom text indicating the market has closed for the day, if the time is after 5 o'clock.

    Thanks again.

    #XPression


  • 12.  RE: Timestamp conversion

    Posted 03-09-2012 02:56
    Also noticed an issue when it is between midnight and 1am; it would show the time as 00:10am instead of 12:10am..

    Here it is updated again:



    dim timestamp as date

    dim hr as integer

    timestamp = text

    hr = Hour(timestamp)

    ' Add the Month Day, Year

    text = MonthName(Month(timestamp)) & " " & Day(timestamp) & ", " & Year(timestamp) & " "

    ' Add the hours (subtracting 12 from anything over 12

    if (hr > 12) then

    text = text & (hr - 12)

    else if (hr = 0) then

    text = text & "12"

    else

    text = text & (hr)

    end if

    text = text & ":" & Right("0" & Minute(timestamp), 2)

    ' Make sure that 00 shows as AM and 12 shows as PM

    if (hr >= 12) then

    text = text & "pm"

    else

    text = text & "am"

    end if



    #XPression


  • 13.  RE: Timestamp conversion

    Posted 03-09-2012 19:13
    That's not much of an issue. The feed only updates between 10am-7pm... but I will keep that in mind for other applications. Thanks!

    #XPression