Tuesday 27 January 2015

UFT - QTP - Function for getting current date in YYYY-MM-DD-HH-MM-SS format


Some time you may have the need to format date and time in various formats.. hope this function will help you align your needs.


Function for getting current date in YYYY-MM-DD-HH-MM-SS format


Function GetFormatedCurrentDate()
 GetFormatedCurrentDate = 0, 
IfLen(Month(now)) = 1Then
  CurrentMonth = 0 & Month(now)
   else
  CurrentMonth = Month(now)
EndIf
IfLen(Day(now)) = 1Then
 CurrentDay = 0 & Day(now)
else
 CurrentDay = Day(now)
EndIf
IfLen(Hour(now)) = 1Then
 CurrentHour = 0 & Hour(now)
else
 CurrentHour = Hour(now)
EndIf
IfLen(minute(now)) = 1Then
    Currentminute = 0 & minute(now)
    Else
    Currentminute = minute(now)
EndIf
IfLen(Second(now)) = 1Then
    CurrentSecond = 0 & Second(now)
    else
    CurrentSecond = Second(now)
EndIf, 
 GetFormatedCurrentDate = Year(now) & - & CurrentMonth & - & CurrentDay & T & CurrentHour & : & Currentminute & : & CurrentSecond", 
EndFunction



 

No comments:

Post a Comment