Discussion:
Using Date Time Format
(too old to reply)
sumitrishi
2006-03-20 18:12:00 UTC
Permalink
Can some one please help me in using the string format functions related to date and time?
The help says you can use format strings like "mm/dd/yy" but if I try to do something like this in a sequence step

str(Parameters.StartDate.Text,"mm-dd-yy")
the expression wouldnt evaluate . And I have to do a workaround just to  append a zero infront of the day or month incase they are less than 10.
 
Thanks
Sumit
 
sumitrishi
2006-03-21 00:12:08 UTC
Permalink
I read it in teststand help . Attached is a snapshot of it . And I might be just looking at the wrong place.
And here is what I am trying to accomplish. I have it finished already but I was thinking if someone can suggets an easier way

Locals.Header +="Test Start Time" + ","+ ( Locals. StartDate. Month <10 ? str( Locals. StartDate. Month, "0"):str( Locals. StartDate. Month)) + "-"+(Locals. StartDate. MonthDay <10 ? str( Locals. StartDate. MonthDay, "0"):str( Locals. StartDate. MonthDay))+"-"+ Mid( str( Locals. StartDate. Year),2 , 4 )+" "+(Locals. StartTime. Hours <10 ? str( Locals. StartTime. Hours, "0"):str( Locals. StartTime. Hours))+"-"+(Locals. StartTime. Minutes <10? str( Locals. StartTime. Minutes, "0"):str( Locals. StartTime. Minutes))+ "\n"
 
Trying to print the time in mm-dd-yy hh-mm format
Thanks,
Sumit


TSHelp.jpg:
Loading Image...
sumitrishi
2006-03-21 18:42:27 UTC
Permalink
Thanks Antonio!
 
Your answer/solution was just perfect.
 
-Sumit
 
Antonio Lie (NI)
2006-03-21 18:42:26 UTC
Permalink
Sumit,
The format strings help document is not related to the Str() function.I can see why you got confused though.The Format Strings listed in that document are used in your system regional and languages options.Start->Control Panel->Regional and Language Options ->Customize.If you change those settings, it will affect the way your entire system displays date and time.That also will affect the way TestStand displays the standard date and time.
Going back to the string formatting issue:
The correct way to format your string will be the following:
Locals.Header = "Test Start Time: " +  Str(Locals.StartDate.Month,"%02u") + "-" + Str(Locals.StartDate.MonthDay,"%02u") + "-" + Right(Str(Locals.StartDate.Year,"%u"),2) + " " + Str(Locals.StartTime.Hour,"%02u") + ":" + Str(Locals.StartTime.Minutes,"%02u") + ":" + Str(Locals.StartTime.Seconds,"%02u") +"\n"
Notice that the format string &nbsp;is "%02u". It indicates that the width should be always 2 and if it is less than 2 it should prefix 0's.Check the "printf" documentation for more information: <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_printf.2c_.wprintf.asp" target="_blank">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_printf.2c_.wprintf.asp</a> Notice that I used the "Right()" function instead of the "Mid()" function.I am also attaching a TestStand 3.0 sequence file that uses the "Time()" and "Date()" functions to obtain the current time.I save them under local container variables similar to yours and finally format them using the previous expression.
Hope it helps.
If you have any question let me know.
Antonio Lie.Message Edited by Antonio Lie (NI) on 03-21-2006 12:24 PM


FormattingExample30.seq:
http://forums.ni.com/attachments/ni/330/10265/1/FormattingExample30.seq
Antonio Lie (NI)
2006-03-21 00:12:08 UTC
Permalink
This post might be inappropriate. Click to display it.
Continue reading on narkive:
Loading...