Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Date Format...

Status
Not open for further replies.

MrSatan

Programmer
Jul 16, 2002
25
AU
Hi All,

Is there any function that can use to convert the date format from yyyymmdd into yyyy-mm-dd or from yyyy-mm-dd back to yyyymmdd?

Currently I need to use something like

SUBSTR(Date, 1, 4) + '-' + SUBSTR(Date, 5, 2) + '-' + SUBSTR(Date, 7, 2)

Thanks in advance.

MrSatan.
 
Try this out:

MyDate="20031130"
?MyDate

MyDate=TRANSFORM(MyDate, "@R ####-##-##")
?MyDate

MyDate=chrtran(MyDate,"-","")
?MyDate

Brian
 
If that doesn't fit your needs, and you don't find a function to fit your needs, you can always create a user-defined-function (UDF) to do that for you.

* call udf
lcNewDate = MYDATE(DATE())


* udf
FUNCTION myDate
LPARAMETER tcDateIn

RETURN SUBSTR(tcDateIn, 1, 4) + '-' + SUBSTR(tcDateIn, 5, 2) + '-' + SUBSTR(tcDateIn, 7, 2)



Jim Osieczonek
Delta Business Group, LLC
 
The suggestion from Brian is exactly what I want. Thank you very much for both of you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top