Wednesday, May 27, 2009

Convert DATE Format from any Format to Required Format

With below tow ways we can convert date fromat from current format to required date data type format.
way 1:-
Code :-
Dim xlsCurrentDate
Set xlsCurrentDate=GetObject("","Excel.Application")
MsgBox xlsCurrentDate.Text("5/27/2009", "YYYY-MM-DD")
Set xlsCurrentDate=Nothing

OUTPUT :- 2009-05-27

way 2:-
dim Val, DateConvert, formatDate
Val="5/27/2009"
DateConvert=Cdate(Val)
formatDate=Year(DateConvert)&"-"&Month(DateConvert)&"-"& day(DateConvert)
msgbox formatDate

OUTPUT :- 2009-05-27

No comments:

Post a Comment