Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DateFormat help
#1
I need the script for displaying date format exactly as below..

eg: if date is may 31 2011 then it has to display as - "2011-05-31"

For example if the date is "01/02/2012" then it should display as "2012-02-01" and it should not display as "2012-2-1"

Please help

Reply
#2
Hi
Use format(dtDate, "yyyy-MM-dd") function. Just check if the function is Format or FormatDate only.
Reply
#3
Verified but its throwing error

currDate1 = FormatDateTime(dtDate, "yyyy-mm-dd")
PRINT currDate1

Type mismatch: '[string: "yyyy-mm-dd"]'

"currDate1 = FormatDateTime(dtDate, "yyyy-mm-dd")".
Reply
#4
Hi... You can get Date in D, M, YYYY format using DatePart method. In order to display 5 as '05', You need to comeup with ur own function. As far as i know, there is no such method in VBScript.
Reply
#5
Hi,

You can try with the below ways:

Way1: Use FormatDateTime built-in function ( Refer the QTP help file for more info.)

Way2: Refer the below code

Code:
x="May 31 2011" Dpart=DatePart("d",x) Mpart=DatePart("m",x) Ypart=DatePart("yyyy",x) If Dpart<=9 then Dpart="0"&Dpart End if If Mpart<=9 then Mpart="0"&Mpart End if RequiredDateVal=Ypart&"-"&Mpart&"-"&Dpart Msgbox RequiredDateVal

Reply
#6
You can use this...

Code:
Function FormatYYYYMMDD(timeStamp) Dim dateMonth : dateMonth = DatePart("M", timeStamp) Dim dateDay : dateDay = DatePart("D", timeStamp) Dim dateYear : dateYear = DatePart("YYYY", timeStamp) Dim dateString dateString = dateYear If dateMonth < 10 Then dateString = dateString & "0" & dateMonth Else dateString = dateString & dateMonth End If If dateDay < 10 Then dateString = dateString & "0" & dateDay Else dateString = dateString & dateDay End If FormatYYYYMMDD = dateString End Function
Reply
#7
Vins and chalam

Sorry guys..just b4 i saw ur replies...i also got solution as below..thanks a lot

Code:
currDate = FormatDateTime(Date, 2) year1 = right(currDate, 4) month1 = mid(currDate, 4, 2) day1 = left(currDate, 2) newdateformat =year1& "-" &month1& "-" &day1 PRINT newdateformat
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)