Graphics

 View Only
  • 1.  Time Formatting

    Posted 07-24-2019 23:14

    Hi All - 

    I have a data feed that provides me kickoff times in this format '8/9/2017 7:30:00 PM.' I'd like to display this as 7:30 PM. I was able to split the string between the data and time then use the left function to display just 7:30. My script is below.

    dim ETTime as string

    ETTime = Split(Text, " ", 2)(1)

    if InStr(text, "PM")>0 then
    Text = left(ETTime,4) & " PM {11}MST"
    end if

    My first problem is if the hour is a two digit number ie. 12:00 then my script won't work. My second problem is the times are listed in ET and i'm in MT so in my example I need the time to display as 5:30pm.

    Any help on any portion of this would be great!! Thanks!



  • 2.  RE: Time Formatting

    Posted 07-25-2019 13:50

    A couple of thoughts on this - one would be that with visual logic, you can split your string into the sub sections required and feed into the date/time block to create 'valid' date/time info you can then take back out of the date /time decoder block. I have a similar function running on my setup. To split your string, instead of doing it by number of chars, split it based on delimeter, so use the space " " to isolate the date from the time using the substring block. In my attached example, I take a text string date, such as "JUNE 4, 2019", and turn it into a valid year, month and day to feed an encode date time block, then decode that to get the day of the week, and translate it to French to show the day, e.g. Friday / Vendredi.

    Hope this helps you.


    #XPression


  • 3.  RE: Time Formatting

    Posted 07-25-2019 14:28

    Or:

    Dim Time, LocalTime as DateTime
    Dim TimeFormat, LocalFormat, MyFormat, MyTimeFormat as String

    Time = Convert.ToDateTime(Text)

    LocalTime = Time.AddHours(-2)
    LocalFormat = "hh:mm tt"
    TimeFormat = Format(CDate(LocalTime), LocalFormat)

    MyFormat = "hh:mm"
    MyTimeFormat = Format(CDate(LocalTime), MyFormat)

    If right(TimeFormat,4) = "a.m." then
    Text = MyTimeFormat & " AM {11}MST"
    Else
    Text = MyTimeFormat & " PM {11}MST"
    End If

    Have FUN!
    Gabriel


    #XPression


  • 4.  RE: Time Formatting

    Posted 07-25-2019 21:30

    Awesome! thanks guys. I used the script and it worked great, the visual logic gave me some insight for other situations as well.


    #XPression