Print Page | Close Window

convert string to datetime

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=16132
Printed Date: 28 Apr 2024 at 2:01pm


Topic: convert string to datetime
Posted By: ankita
Subject: convert string to datetime
Date Posted: 10 Apr 2012 at 6:53am
hi

*** 29/03/12 21:50:35(Abhishek Ranjan) ***
Done. PFA Logs.
*** 29/03/12 21:50:34(Abhishek Ranjan) ***
Done. PFA Logs.
*** 29/03/12 17:23:21(Shailey Narula) ***
a
*** 29/03/12 17:22:49(Shailey Narula) ***
a
*** 29/03/12 17:22:49(Shailey Narula) ***
a
*** 29/03/12 16:49:07(Deepika Katoch) ***
Kindly do the needful.



i extracted the date feild from above by using MID function

((Mid ({OCMQM1.COMMENTS},4 ,18 )))

i got
29/03/12 21:50:35

now this is string trying to convert it into datetime by suing cdatetime formula

its givinging
like this

3/12/2029   9:50:35PM

which is wrong it shuld be 29/03/2012   9:50:35PM





PLS do the needful asap.




Replies:
Posted By: lockwelle
Date Posted: 10 Apr 2012 at 7:58am
break up your date into the individual components and then use DateTime...check help for the parameters


Posted By: ankita
Date Posted: 10 Apr 2012 at 8:41am
Sorry not understood this one ......




Posted By: lockwelle
Date Posted: 10 Apr 2012 at 10:56am
you're passing a string, but it is not distinct as to what is the month day and year.
 
separate your string into a year, month, day, hour, minute, second and then combine them using DateTime...then you will have variable that is the date that you think it is.


Posted By: ankita
Date Posted: 10 Apr 2012 at 4:50pm
not done.....

Tried alot it takes day as month sometimes while converting to datetime .

Thanks for your replies







Posted By: rkrowland
Date Posted: 10 Apr 2012 at 11:17pm
Use the following formula;
 
numbervar y := 2000 + tonumber(mid({OCMQM1.COMMENTS},11,2));
numbervar m := tonumber(mid({OCMQM1.COMMENTS},8,2));
numbervar d := tonumber(mid({OCMQM1.COMMENTS},5,2));
numbervar h := tonumber(mid({OCMQM1.COMMENTS},14,2));
numbervar n := tonumber(mid({OCMQM1.COMMENTS},17,2));
numbervar s := tonumber(mid({OCMQM1.COMMENTS},20,2));
datetime(y,m,d,h,n,s)
 
Regards,
Ryan.
 
EDIT: Assumes all your dates will be post 01/01/2000...


Posted By: ankita
Date Posted: 10 Apr 2012 at 11:30pm
Thnaks alot it worked for me.



Print Page | Close Window