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!

Convert Date to DateTime

Status
Not open for further replies.

MeganHall

IS-IT--Management
Oct 2, 2002
1
NZ
I am having trouble converting a date to a datetime so that I can use the DateTimeDiff functionality. I am going through the following steps:

1. Convert Date to String
= ToText(?DateField)
30/09/2002 converts to 30/09/2002

2. Convert String to DateTime
DTSToDateTime ({TextDateField}+",0,0,0")

However all I seem to come up with is 00:00:00
I have tried this with the date in different formats, including not using /s eg. Date = 30092002, and 09302002 and 20020930 and 300902 etc etc...

Just started using Crystal and am beginning to despair - Can anyone help?
 
Well, I guess firstly, to display DateTime alternatives to your date field, you could assign your dates to a variable:

DateTimeVar DateTimeConverter := DateTime({YourDateField},0,0,0)

But, whatever means you use to convert your date field into datetime, you're always going to end up with a static time. Like, in the example above, the time is always going to be 0:00:00.

If all this is just so that you can use the DateTimeDiff function, there is actually a DateDiff function which - in this case - will do just what the DateTimeDiff function would do, and it'll save you the added hassle of worrying about conversion.

All the best,

Naith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top