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

DatePart Problem

Status
Not open for further replies.

clydejones

Programmer
Jan 11, 2001
153
US
Hi All,
I'm trying to make a date from the month and year of a parameter. Here is the formula:

datePart("m",{?fromDate})&"-01-"&datePart("yyyy",{?fromDate})

January 1, 2003 was entered for the fromDate parameter, I was expecting 01-01-2003. However, I got 1.00-01-2,300.00. If I try to cast it to a dateTime, I get "Bad date-time format string". Any suggestions>

Thanks In Advance,
Clyde
 
Hmmm - I started to mess around with your formula, then thought - why not just format it that way? If your parameter is defined as a date, drop the parameter on your report, right click on it, go to Format Field, go to Customize (depending on your version of Crystal) and set it up to display it in the format you want it.

Peter Shirley
 
Peter,

Thanks for your reply. The parameter is already formated as a date. This report will be run on a monthly basis and there may be some days there is no data for a particular date though not likely. However, I want to show the date. Any more ideas?

Thanks Again,
Clyde
 
You can get the display you want two ways. The easiest is just to do as Peter suggested--drag the parameter onto the report canvas, right click->format field->date/time->customize and choose hyphens for the two separators, and choose the length of each of the fields, month, day, year.

Otherwise, you can use:

totext(datepart("m",{?fromDate}),"00") & "-01-"& totext(datepart("yyyy",{?fromDate}),0,"")

-LB
 
lbass,

Thanks for your answer. I believe you provided me the answer with the toText() function. I guess I was close but no cigar. You get the cigar.

Clyde
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top