Converting a char to a date in Crystal???

Jack Tripper
10-12-2004, 11:39 AM
I know this is probably easy but nobody has given me a clearcut answer on how to specifically do this. I have a VERY simple 2 field report, the datetime field reads in this format 'YYYYMMDDHHMMSS' so for instance today at 11:59 would look like: 20041012115900 and I want it to look like this '10/12/2004 11:59:00'


How and where can I convert this value to display a DateTime values on the report? A code example would be great!

MKoslof
10-12-2004, 06:51 PM
Basically use the dateTime method that takes a string argument broken down into the valid proportions needed Year, Month, day, hours, minutes.

1) Create a formula that takes your string and parses it out into stringvars, call them gYear, gMonth, gDay, gHours and gMinutes

2) Then have a DateTime variable that converts this into the proper date time:



gYear:= Left(myTable.MyDateField, 4); 'parse out the left four for the year
gMonth:= 'parse out the month
gDay:= 'parse out the day, etc...finish all variables

myDateTime:=DateTime(gYear, gMonth, gDay, gHours, gMinutes);
myDateTime

Jack Tripper
10-13-2004, 07:09 AM
Thanks for the response, I tried something slightly different yesterday and it worked.

First - I made a Formula field called 'DateConv'
Then in the formula editor (for DateConv) I did this:

CDateTime ( val(left({MyTable.MyField},4)),val(mid({MyTable.MyField},5,2)),val(mid ({MyTable.MyField},7,2)),val(mid({MyTable.MyField},9,2)),val(mid({MyTa ble.MyField},11,2)),val(right({MyTable.MyField},2)) )

Then inserted the formula field on the report, and voila!!

MKoslof
10-15-2004, 05:35 PM
Looks good :). Let us know if you need more assistance.

Jack Tripper
10-20-2004, 08:00 AM
Thanks :D

Actually I do have one more related question. How can I do this in vbCode?

MKoslof
10-20-2004, 05:44 PM
Look into the DateSerial() and TimeSerial() function.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum