Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: need help with date(s) Post Reply Post New Topic
Author Message
cynthiakelly
Newbie
Newbie


Joined: 24 Mar 2011
Location: United States
Online Status: Offline
Posts: 8
Quote cynthiakelly Replybullet Topic: need help with date(s)
     Posted: 24 Mar 2011 at 8:22am
This is a little lengthy..please bear with me.
 
We have a date-time field that doesn't necessarily have the hour:min:sec portions populated. In those cases, I have to use the a number field that contains only HHMM info.
 
I need to use either ...
 - the date-time field in its entirety
OR
 - the date portion of the date-time field concatenated with the HHMM field
 
I've been wrestling lots of date functions to create a complete date-time field, but, so far I haven't had any luck. HELP!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Mar 2011 at 10:21am
1. in the datetime field with the missing times do they come in as date at midnight?
IP IP Logged
cynthiakelly
Newbie
Newbie


Joined: 24 Mar 2011
Location: United States
Online Status: Offline
Posts: 8
Quote cynthiakelly Replybullet Posted: 25 Mar 2011 at 3:12am
Yes, I think that's the default.
HH:MM:SS are zero if not specified, so 00:00:00 would be midnight, the start of the day.
IP IP Logged
cynthiakelly
Newbie
Newbie


Joined: 24 Mar 2011
Location: United States
Online Status: Offline
Posts: 8
Quote cynthiakelly Replybullet Posted: 26 Mar 2011 at 7:43pm
Pinch  I have continued to search the web for an answer. Please help ..
I haven't used VB date functions in a while; and I'm relatively new to the CrystalReports environment.
 
I need to create a complete date-time field. If necessary, I can extract the year, month, and day portions from my date-time field; and, I can extract the hour and minute portions from my HHMM field.
 
I need to know what function should be used to create a complete date-time field.  I've tried CDate, but apparently I'm not formatting everything correctly. Thanks in advance for any suggestions or advice.
 
Cynthia
IP IP Logged
yggdrasil
Senior Member
Senior Member
Avatar

Joined: 19 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 150
Quote yggdrasil Replybullet Posted: 28 Mar 2011 at 3:27am
Possibly longwinded, but you could just build it up from strings & substrings.
The function for Datetime is
Datetime(YYYY,MM.DD,HH,MM,SS)
 
From your time function TIME   HH := totext(left(TIME,2), 0)
 and MM := totext(right(TIME,2),0)
 
(I think, if I've understood you correctly)
 
So if in your datetime function HH and MM are 00 then substitute the above.
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 28 Mar 2011 at 3:39am
sorry was out for a bit..
try
if time(datetime_field)<>time(00,00,00) then datetime_field
else
datefield + time(tonumber(if {timefield}>=1000 then
left(totext({timefield},0,''),2) else left(totext({timefield},0,''),1)),
tonumber(right(totext({timefield},0,''),2)),
00)
 
IP IP Logged
cynthiakelly
Newbie
Newbie


Joined: 24 Mar 2011
Location: United States
Online Status: Offline
Posts: 8
Quote cynthiakelly Replybullet Posted: 01 Apr 2011 at 6:22am
Thanks, you two! 
 
I combined suggestions form both of you and got the result I needed.
IP IP Logged
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