Showing results for 
Search instead for 
Did you mean: 

Question with using scan from string to get a timestamp

Go to solution

So Im using Scan from string with this pattern  " %<%d.%m.%Y>T " to get a time stamp from a string like "30.05.2019".

The problem is that I get 30.05.2016 1:00:00 as time stamp instead of 30.05.2016 0:00:00. This has caused so many bugs in my program any idea how to fix it? 


0 Kudos
Message 1 of 10

Is this the -1 hour local timestamp because a timestamp can be in UTC or Local.

You should play around with the boolaen is UTC on create 

greetings from the Netherlands
0 Kudos
Message 2 of 10
Accepted by 77maxmustermann

I'll look into it thanks. Otherwise I found another solution just add 00:00:00 to the string. 

0 Kudos
Message 3 of 10

That does not seem to be a good solution, can you post that subvi?

greetings from the Netherlands
0 Kudos
Message 4 of 10

Yep here you go

0 Kudos
Message 5 of 10

When I run your code (in the US), I get a two-line string with the first line "12:00:00.000AM" and the second line "6/5/2015" (the US default order is month, day, year).  By changing the indicator (output 1) Display Format (Advanced Editing Mode) to "%<%x>T", this gives a 1-line output of "6/5/2015", which seems to be what you might want.


Bob Schor

0 Kudos
Message 6 of 10

The question is what do you do with that timestamp value once you've created it from the string?


Timestamps are significant in that they both contain a date and a time value in it.  Yet some times in programming, you really only want one or the other.  Like in this case, you have a date, but your original input has no time information associated with it.  So what do you want the time to be?  MIdnight UTC?  Midnight your local timezone?  Some other time of day?  You just don't care what it is?  For instance, you might just want to know if a particular value matches a particular date on the calendar.


Other times you may not care about the date, only the time.  You want to compare something to 9am, no matter what the date.  For example, is the current time before 9am or after 9am?  You might always be assuming the current date, or some date in the past or future.  But a timestamp of 9am to compare to has a specific date assigned to it.


So what do you do in either of these situations?  You need to manipulate the timestamp value.  Either give assign a specific date you don't have in your original information.  Or assign a specific time.  Look at the other functions in the Time palette.  There are ones that work with clusters called time records.  There you can assign specific values of dates such as months, days, years, or hours, minutes, seconds, to create timestamps where you can fill in the missing data elements to create a specific  date/time timestamp value..

0 Kudos
Message 7 of 10

Im using the 24 Hour system. 

I have 3 inputs in the program. a time variable and 2 time constants.

The program is quite simply if the time variable is between those 2 constants then I get true as a boolean. I have for example 5.3.2015 00:30 (or 3.5.2015 if you're from america). if its between 4.3 and 6.3 then I get true. the problem I had is that I always got 4.3.2015 1:00:00 when converting the date instead of 4.3.2015 0:00:00 which led to some nasty errors. the method I used worked. but still I was still curious how to fix this problem without using any shenanigans


0 Kudos
Message 8 of 10

What I'm saying doesn't matter whether you are using a 24 clock or a 12 hour am/pm clock.


I'm just describing how it can be challenging to work with LabVIEW timestamps which have a date and time of day component, whether you show them or not.


So there always will be some sort of shenanigans to fill in and standardize the missing parameters for the timestamp.  I think defining a midnight time in your string to go with your date string is as good of a method as any.

0 Kudos
Message 9 of 10

When I see an "off-by-one-hour" situation, I think about Daylight Savings Time, which (in the US, in June) subtracts an hour from the UTC-TimeZone-adjusted time.  Here's a Snippet that shows the current Date/Time in the eastern US, and another routine that takes the Time Stamp, converts it to display just the date (in whatever format you've set as your PC standard, d/m/y or m/d/y) using Format into String, then isolates Day, Month, and Year using Scan from String.  Very simple.

Scan from string for TimeStamp.pngScan from String for Timestamp

Bob Schor

0 Kudos
Message 10 of 10