#1
|
|||
|
|||
Formatting Date and Time
Is there an easy way to format the current date and time in the following format:
dd/mm/yyyy;hh:mm[a|p] Here is a sample: 12/19/2003;04:34p I would like to set a macro with the date and time of the current build in the format above so that I can run a SourceSafe history report of all changes since the last build. I would appreciate any suggestions that you might have. Thanks, Shane |
#2
|
|||
|
|||
I think VSS actually wants the date in mm/dd/yy format. Anyway, you can tweak this code as necessary (paste into your global or project scripts in the Script Editor):
Function FormatDateVSS() ' returns the current date+time in the form ' mm/dd/yy;hh:mm[a|p] Dim dte, h, p dte = Now h = Hour(dte) If h >= 12 Then p = "p" h = h - 12 Else p = "a" If h = 0 Then h = 12 End If FormatDateVSS = vbld_PadLeft(CStr(Month(dte)), 2, "0") & "/" & _ vbld_PadLeft(CStr(Day(dte)), 2, "0") & "/" & _ vbld_PadLeft(CStr(Year(dte)), 2, "0") & ";" & _ vbld_PadLeft(CStr(h), 2, "0") & ":" & _ vbld_PadLeft(CStr(Minute(dte)), 2, "0") & p End Function And use in a step field like [FormatDateVSS] For instance, <step action='Log Message' type='0'> <Message>formatted date = [FormatDateVSS]</Message> <indent type='3'>1</indent> <name>New Step</name> </step> |
#3
|
|||
|
|||
Actually VSS uses the locale to determine the date format. European users of VSS will (mostly) have dates in dd/mm/yy format, whilst North American users (and others) will have the mm/dd/yy format
|
#4
|
|||
|
|||
Thanks for the info.
The VBScript you posted worked fine, but I was also trying to do it with JScript and it returns <object> instead of the formatted date and time. I also tried some other JScript functions like vbld_FormatDateTime and they alse returned <object>. Is this a limitaion of using JScript or is there something else that I need to do? |
#5
|
|||
|
|||
You should be able to use .toString() on any JScript expression to force it to be evaluated as a string.
|
#6
|
|||
|
|||
I did not realize that you had to use parenthasis when calling a JScript function from a step field.
I was just using [FormatDateVSSJScript] when I should have been using [FormatDateVSSJScript()] Thanks! |
|
|