February 08, 2008

Tip10 - Get TimeStamp for Current time

It will be useful to create unique files and set the dateTime info whenever needed. Following code snippet will prepare timestamp based on that time.

[+] String GetTimeStamp()
//Purpose: To get current time stamp in the given format
String sDate, sTime
String sTcFile
STRING sPrefix

GetCurrentDateTime (sDate, sTime,"yyyymmdd","hhnnss" )
sPrefix = "{sDate}{sTime}"
return sPrefix

[+] public void GetCurrentDateTime(out String sDate optional, out String sTime optional,String sDateFormat null optional,String sTimeFormat optional)
// Purpose: Current date and time are taken from the system.
DateTime dtmCurrent

[+] if (IsNull(sDateFormat))
sDateFormat = "mm/dd/yyyy"
[+] if (IsNull (sTimeFormat))
sTimeFormat = "hh:nn:ss AM/PM"
dtmCurrent = GetDateTime ( )
sTime=FormatDateTime (dtmCurrent, sTimeFormat)
sDate=FormatDateTime (dtmCurrent, sDateFormat)

0 comments: