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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting the Date into a Character String

Status
Not open for further replies.

Vatchunter

Technical User
Aug 21, 2004
43
US
Hi all,

How is the best way to capture the date and insert it into a character string? Basically, this is going to be a combination of the source of the data, and the date the my program was run on it.

The result I need is this: "File Source 03/11/2015"

Thanks for all your help!
 
Make sure you don't use slashes, they are not allowed in file names or rather lead to creating folders.

DTOS() is best for a file name, just the 8 digits in YYYYMMDD format.

Bye, Olaf.
 
Thanks Olaf, this code is just to populate a "source" field within the file that my program opens, and sets up for further evaluation.

Appreciate the quick responses.

vatchunter

 
One of the underused functions is TextMerge().
Code:
?textmerge("File Source <<date()>>")
 
TRANSFORM has that advantage to transform (almost) any type to char (besides general). But DTOC(DATE()) can't fail.

TEXTMERGE is fine, especially with longer texts and more to merge in, you simply put any expression between << and >> you'd otherwise also be able to print via ? command, instead of using "stringpart1"+expression+"stringpart2"+expression+...

Bye, Olaf.
 
You have several choices -- DTOC(), DTOS() and MDY().

DTOC() will convert a date to character format based on setting of SET DATE
DTOS() will convert a date to format YYYYMMDD
MDY() will convert a date to Month Day, Year (e.g. January 1, 2015); based on setting of SET DATE and SET CENTURY
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top