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!

Converting to a Date from a Number

Status
Not open for further replies.

NoExperienceInUtah

Technical User
Apr 30, 2003
16
US
I am using Crystal Reports with Softpro's ProForm. I have NEVER programmed before and need some help.

ProForm stores its dates in an odd format. It stores them as a number in the 20030430 format (April 30, 2003.) I am trying to create reports, but I don't want to have to teach my employees that when they are prompted for a date, they have to enter it like that. I'd like them to be able to put 04/03/2003 in the prompt and have the formula take care of the rest. I'm sure there is a formula that will take a standard date and convert it into the above formula so that it can be used with the database.

I don't know that I quite explained that right, but hopefully someone out there will understand what I need and be able to help. THANK YOU!
 
Go to the crystal decisions website and download the numbertodate() UFL. This function takes an 8 digit integer in a YYYYMMDD format and converts into a real date.

Here is the link:



Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
dgilsdorf@trianglepartners.com
 
I am REALLY new to Crystal Reports (I've had it for two days now.) How do I add that function that you pointed me to to my report?

Also, when I run the report, it asks me for a date range, but I can't get the range I input to search the dates in the database because they are all in numeric format. What do I do to make them mesh?

Thanks for your patience.
 
To add the function in crystal you download it and install it. Did you do this? If so the function will appear in the formula editor window under "additional functions".

Your report should ask for a date range, however, you need to tie the date range parameter into your record selection formula in order for this to select the proper records. Your record selection formula should look like the following:

Numbertodate({YourNumericDateField}) in {?DateRangeParameter}

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
dgilsdorf@trianglepartners.com
 
Or you can create your own formulas as I'm not sure that dgillz solution will pass the SQL processing down to the database:

@startdate
val(totext(year(minimum({?StartDate})),0,"")+
iif(len(totext(month(minimum({?StartDate})),0,"")) = 1,"0"+totext(month(minimum({?StartDate})),0,""),totext(month(minimum({?StartDate})),0,""))+
iif(len(totext(day(minimum({?StartDate})),0,"")) = 1,"0"+totext(day(minimum({?StartDate})),0,""),totext(day(minimum({?StartDate})),0,"")))

@enddate
val(totext(year(maximum({?StartDate})),0,"")+
iif(len(totext(month(maximum({?StartDate})),0,"")) = 1,"0"+totext(month(maximum({?StartDate})),0,""),totext(month(maximum({?StartDate})),0,""))+
iif(len(totext(day(maximum({?StartDate})),0,"")) = 1,"0"+totext(day(maximum({?StartDate})),0,""),totext(day(maximum({?StartDate})),0,"")))

In the record selection formula use:

{table.datestring} >= @startdate
and
{table.datestring} <= @enddate

-k
 
SynapseVampire,

I have a question. How can I tell if the selection formula will pass thru to SQL?

I have seen many of your posts regarding this subject but it is time for me to get to understand this concept fully.

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
dgilsdorf@trianglepartners.com
 
Once you extract the function from the zip file, you should copy the DLL to the Windows\Crystal folder. Then the next time you open CR it will read this function into the list of available functions.

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Expert's Guide to Formulas / Guide to Crystal in VB
- tek@kenhamady.com
 
Synapse,

In you solution for @StartDate and @EndDate, would

Date(ToText(Minimum({?StartDate}),&quot;####,##,##&quot;)) and
Date(ToText(Maximum({?StartDate}),&quot;####,##,##&quot;))

Work ok?

Reebo
Scotland (Sunny with a Smile)
 
dgillz: Check the Database->Show SQL Query

Everything in the Record Selection Formula should be reflected there.

Reebo: I don't think so, though you could use:

val(ToText(minimum({?startdate}),&quot;yyyyMMdd&quot;))

I've had some bad experiences when trying to get Crystal to pass SQL when I used a formatting mask in the totext, but I tested and the above works.

-k
 
Synapse,
I tried inserting your formula into my Report, but when I try to save it, it tells me that the summary/running total fields can't be created. What does that mean?
 
I'm not using a summary or running total, so I've no idea why yours isn't working, please post what you tried.

-k
 
Set your parameter to be a date.. in the selection formulat


{table.datestring} >= (datepart(&quot;yyyy&quot;,@startdate) * 10000) + (datepart(&quot;m&quot;,@startdate) * 100) + datepart(&quot;d&quot;,@startdate)
and
{table.datestring} <= (datepart(&quot;yyyy&quot;,@enddate) * 10000) + (datepart(&quot;m&quot;,@enddate,) * 100) + datepart(&quot;d&quot;,@enddate)

Lisa
 
Or:

{table.datestring} >= val(ToText(minimum({?startdate}),&quot;yyyyMMdd&quot;))
and
{table.datestring} <= val(ToText(maximum({?startdate}),&quot;yyyyMMdd&quot;))

-k
 
I didn't think I was using summary or running total fields. How can I stop from using them? They aren't anywhere on my report.
 
I copied exactly what you had posted and created a new formula and pasted it into it.

val(totext(year(minimum({?StartDate})),0,&quot;&quot;)+
iif(len(totext(month(minimum({?StartDate})),0,&quot;&quot;)) = 1,&quot;0&quot;+totext(month(minimum({?StartDate})),0,&quot;&quot;),totext(month(minimum({?StartDate})),0,&quot;&quot;))+
iif(len(totext(day(minimum({?StartDate})),0,&quot;&quot;)) = 1,&quot;0&quot;+totext(day(minimum({?StartDate})),0,&quot;&quot;),totext(day(minimum({?StartDate})),0,&quot;&quot;)))
 
Do you have a parameter called StartDate?

You might instead go into the record selection formula (Report->Edit Selection Formula->Record) and place something like:

{table.datestring} >= val(ToText(minimum({?startdate}),&quot;yyyyMMdd&quot;))
and
{table.datestring} <= val(ToText(maximum({?startdate}),&quot;yyyyMMdd&quot;))

Replacing {table.datestring} with the name of the field in your database.

-k
 
I do have a paramater called startdate. It's a date field, I'll try your second suggestion. Thanks for your patience...This is all extremely new to me.
 
Synapse,
I get the same error if I try to insert the shorter formula into the selection formula. Any more thoughts?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top