NI Home > Community > NI Discussion Forums

LabVIEW

Showing results for 
Search instead for 
Do you mean 
Reply
Member
kkroninger
Posts: 15
0 Kudos
Accepted Solution

Using Format Date/Time String Function Vi

I wanted Labview to display the time in milliseconds and I got that to work. I want to display PM or AM after the milliseconds so it looks like this

 

05/31/11  4:45:39.849 PM

 

I am using %p as you can see in the picture, but it is not working. PM or AM does not show up.

 

What am I doing wrong?

Thanks in advance. 

Trusted Enthusiast
Mark_Yedinak
Posts: 3,056
0 Kudos

Re: Using Format Date/Time String Function Vi

Replace your %H with a %I. %H is 24 hour time which has no A.M or P.M designation. You need to use 12 hour time.



Mark Yedinak

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot

Knight of NI
RavensFan
Posts: 16,072

Re: Using Format Date/Time String Function Vi

[ Edited ]

You need I instead of H for the hour portion.  H is for a 24 hour clock, so that wipes out any meaning for AM/PM.

 

I've never used Format into Date/Time String, and just use Format into String.  This gives you the ability to add other data into the string.

 

 

Knight of NI
RavensFan
Posts: 16,072
0 Kudos

Re: Using Format Date/Time String Function Vi

Why is it "H" for the 24 hour clock and "I "is for a 12-hour clock?  "I" is not logical at all other than the fact is follows "H".

 

I think it would make more sense the other way around.  "H" for the 12 hour clock and I for the 24-hour clock, since 12 comes before 24.  Also, "I" could mean "international".

Trusted Enthusiast
Darin.K
Posts: 3,961

Re: Using Format Date/Time String Function Vi

 


Ravens Fan wrote:

Why is it "H" for the 24 hour clock and "I "is for a 12-hour clock?  "I" is not logical at all other than the fact is follows "H".

 

I think it would make more sense the other way around.  "H" for the 12 hour clock and I for the 24-hour clock, since 12 comes before 24.  Also, "I" could mean "international".


That notation is the ISO-C standard so you'd probably have to bring it up with them.  I tend to remember that 'I' stands for illogical and the 12-hour clock certainly qualifies.

Knight of NI
RavensFan
Posts: 16,072
0 Kudos

Re: Using Format Date/Time String Function Vi

I didn't realize there was an ISO standard on shortcuts.

What is interesting is that Excel's custom date codes for a cell format only use an "h".  It is the presence or lack thereof of the AM/PM in the date code that tells it to use the 12 hour clock or the 24 hour clock.

 


Darin.K wrote:
 

 I tend to remember that 'I' stands for illogical and the 12-hour clock certainly qualifies.

You lost me on that comment.

Member
kkroninger
Posts: 15
0 Kudos

Re: Using Format Date/Time String Function Vi

Thank you for everyone who replied. All the comments were insightful and helpful. Thank you. 

 

Trusted Enthusiast
Darin.K
Posts: 3,961
0 Kudos

Re: Using Format Date/Time String Function Vi


Ravens Fan wrote:

I didn't realize there was an ISO standard on shortcuts.

What is interesting is that Excel's custom date codes for a cell format only use an "h".  It is the presence or lack thereof of the AM/PM in the date code that tells it to use the 12 hour clock or the 24 hour clock.

 


Darin.K wrote:
 

 I tend to remember that 'I' stands for illogical and the 12-hour clock certainly qualifies.

You lost me on that comment.


IMO, other than colloquial use, the 12 hour format is woefully outdated.  Using it as a timestamp just does not make sense to me.  There is a two-fold degeneracy which is only broken by a separate am/pm flag (or is it a.m., AM, A.M.) so it takes more space and longer regexes to deal with.  These timestamps are not easily sortable, nor comparable without preprocessing.  That is part of the reason why I think it is 'illogical' to use it (for lack of a better mnemonic).   

 

And the ISO standard is on the C-language, of which these shortcuts are part.  I have a sneaking suspicion that I know what happens under the hood of the Format functions which use time codes...

Knight of NI
RavensFan
Posts: 16,072
0 Kudos

Re: Using Format Date/Time String Function Vi

Okay, I agree with you there.  If I need to do anything that is text based, date and time format, I'll save it as 24hour data so that it can be sortable.  For instance, creating a filename based on date and time,  I'll do a year-month-day 24hr-min-sec format (with whatever punctuation/separators I feel like at the time to be somewhat readable) all zero filled so a month like June is 06, so that alphabetically sorting by that data also causes it to be chronologically sorted.

 

If it is just for the sake of a front panel display for the user to see a time, then I'll use 12 hour with am/pm and a normal month/day/year format so that the user doesn't have to do any mental math.  7:00 pm is meaningful,  1900 requires too much thinking.

Trusted Enthusiast
TCPlomp
Posts: 3,097
0 Kudos

Re: Using Format Date/Time String Function Vi

Raven's I would disagree, but I think you use the default system formatting for any user controls, right?

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!