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!

CONVERTING DATETIME TO NUMBER

Status
Not open for further replies.

shaunk

Programmer
Aug 20, 2001
402
AU
I am running V8.5 against SQL Server.

How do I convert a datetime value to a number representing the number of days since Dec 30 1899 ( I believe this is the base Crystal uses).

I can find the formula to do the opposite (convert a number to a datetime value - this is done useing CDATE) , but not the opposite.

I fear I will have to break the datetime into component parts and manually calculate the number.
 
Crystal does not have a standard for dates, it is the database itself that determines this. In Macola for example, all dates are stored as an 8 digit integer in a YYYYMMDD format, and are converted to "real" dates using the function NumberToDate().

To get the numberof days between a date and 12/30/1899, use the following formula:

Datediff("d",{YourDateField},Date(1899,12,30))

I am not sure this is what you want however. I do not understand your statement about breaking the number into component parts. Software Sales, Training and Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
Thanks dgillz,

Problem solved. I will utilise Datediff function.

In breaking the datetime into components I meant to
employ something like :

YearC := Year({date-time})
MonthC := Month({date-time})
DayC := Day({date-time})

I would then have to work on a case statement to express the month and day as the number of days since the start of the year and end up with something like:

DayNumber := YearC + (Number of Days since start of year)
I would of course use normal Crystal syntax to get it happening.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top