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

how to get mm/dd/yyyy from DateTime var?

Status
Not open for further replies.

peteschulte

IS-IT--Management
Nov 21, 2008
41
US
Hello Fox Coders

I have been clicking around in the help files and trying various ways to get from
Code:
replace billdate with iif(!isnull(billsummary.billdate), datetime(billsummary.billdate),'')
yielding 20081012 to another code expression that would yield 10/12/2008. I can get the former but not convert it to xx/xx/xxxx format for printing. I've been tryi8ng all kinds of conversions. Any immediate help would be much appreciated! If not immediate, I'll probably check after dinner. Anybody there? Thanks! !! !!!


smiletiniest.gif
Pete S
 
Pete's suggestion above is the command you are looking for.

BUT based on your using datetime(billsummary.billdate) in your query you are obviously beginning with something other than a DateTime value.

Now you want to convert the already converted value into a Date value?

Why not just convert the original value directly?

Since the 2nd half of your IIF() statement is a string, I assume that your billsummary.billdate is also a string.

If so then why convert it from:
1. String to DateTime
2. Then from DateTime to Date

Why aren't you just converting it with something like:
Code:
iif(!isnull(billsummary.billdate),CTOD(billsummary.billdate),CTOD("  /  /  "))

Remember that SET CENTURY ON will cause all 4 digits of the year to be displayed by default.

Good Luck,
JRB-Bldr
 
JRB-Bldr,

notice that pete answered himself, no need to pint out to pete, that pete has found an answer. <s>

@pete:
From the replace one can assume, that you don't replace billdate with itself, or do you?

recommended is, to use the format options of the report control to tranform a datetime into a string of your needs. CTOD or TTOD and TRANSFORM is not the only thing that can do that. You can also simply use the datetime field and it's recommended to not change this to string unless really needed, eg if you want a format VFP does not produce.

In a report field control you can set expression to the datetime field, then in the format tab choose that expression to ba a date. Now your options change to chooseing from several things, eg british date format, which would fit your needs, but also the format set in windows, either the long or short format, or, let the report display that datetime in the SET DATE format.

And there you go, you can SET DATE MDY, SET DATE BRITISH, SET DATE AMERICAN, plus you have SET MARK, with which you can choose between "." or "/" as separator for date expressions, also SET CENTURY ON and SET HOURS 24 for the time portion, if you want that.

I'd recommend SET SYSFORMATS ON, SET CENTURY ON, those two are enough to let VFP print the datetimes in the format the user wants and sets in windows. Only override that if you need to differ from the windows settings.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top