Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Editing Dates To Midnight Hour Post Reply Post New Topic
Author Message
dapoole
Newbie
Newbie


Joined: 29 Sep 2010
Online Status: Offline
Posts: 6
Quote dapoole Replybullet Topic: Editing Dates To Midnight Hour
     Posted: 29 Aug 2011 at 3:33am
Hi there,

I have a date field containing fields such as '29/08/2011 13:47:18' and '18/08/2011 11:26:11'. Is it possible to sum this type of data in a formula to the hour of midnight, for example the above would become '29/08/2011 00:00:00' and '18/08/2011 00:00:00' respectively?

TIA
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 29 Aug 2011 at 3:56am

What is your end purpose for doing that? There are a number of processes to do that but depending on the reason there may be even easier approaches.

If is is simply for display you alter how the field looks to only show the date.
If it is for summing per day you can group on the date field and set it to use 'per day'.
You can also truncate it by using date(datetimefield).
You could also convert it to text.
IP IP Logged
dapoole
Newbie
Newbie


Joined: 29 Sep 2010
Online Status: Offline
Posts: 6
Quote dapoole Replybullet Posted: 29 Aug 2011 at 4:24am
It's not for display. I am trying to compare 2 date fields to see if they occured within a day of each other. By rounding down the first date field to midnight (ie the start of the day) then I only want to select the records with dates in the second date field if they occurred after the first date, ie midnight.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 29 Aug 2011 at 7:20am
if i understand you correctly can use datediff
datediff("d",firstday,secondday)=1 to get only values where they are within one day.
if you really want to get to midnight you can use
datetime(year(table.datefield),month(table.datefield),day(table.datefield),0,0,0)
IP IP Logged
dapoole
Newbie
Newbie


Joined: 29 Sep 2010
Online Status: Offline
Posts: 6
Quote dapoole Replybullet Posted: 30 Aug 2011 at 12:53am
Thanks that helped. 
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