Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: convert string to datetime Post Reply Post New Topic
Author Message
ankita
Newbie
Newbie


Joined: 13 May 2011
Online Status: Offline
Posts: 37
Quote ankita Replybullet Topic: convert string to datetime
    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.

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 10 Apr 2012 at 7:58am
break up your date into the individual components and then use DateTime...check help for the parameters
IP IP Logged
ankita
Newbie
Newbie


Joined: 13 May 2011
Online Status: Offline
Posts: 37
Quote ankita Replybullet Posted: 10 Apr 2012 at 8:41am
Sorry not understood this one ......


IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet 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.
IP IP Logged
ankita
Newbie
Newbie


Joined: 13 May 2011
Online Status: Offline
Posts: 37
Quote ankita Replybullet 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





IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet 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...


Edited by rkrowland - 10 Apr 2012 at 11:18pm
IP IP Logged
ankita
Newbie
Newbie


Joined: 13 May 2011
Online Status: Offline
Posts: 37
Quote ankita Replybullet Posted: 10 Apr 2012 at 11:30pm
Thnaks alot it worked for me.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.