Solved

Pull records from last 24 hours in Crystal Reports

Posted on 2011-03-25
12
1,753 Views
Last Modified: 2012-05-11
I need to pull medication administration records for the previous 24 hrs.  The Date and Time fields are separate and are in text form as 20110324 and 20:01.  What syntax do I need to put in the record selector so I can pull records from the previous 24 hours on demand?

Thank you.
Linda
0
Comment
Question by:LindaOKSTATE
  • 6
  • 6
12 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 35220618
Are you looking for the last full day or the 24 hours prior to the datetime of the run?

mlmcc
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 35220636
For the last 24 hours you could use a selection formula like

DateTime(Date(Val(Left({YourDateField},4)), Val(Mid({YourDateField},5,2)), Val(Right({YourDateField},2)))+1,Time({YourTimeField})) >= CurrentDateTime

For the last full day
Date(Val(Left({YourDateField},4)), Val(Mid({YourDateField},5,2)), Val(Right({YourDateField},2)) = CurrentDate -1

mlmcc
0
 

Author Comment

by:LindaOKSTATE
ID: 35232768
I tried this one: DateTime(Date(Val(Left({YourDateField},4)), Val(Mid({YourDateField},5,2)), Val(Right({YourDateField},2)))+1,Time({YourTimeField})) >= CurrentDateTime

Time({YourTimeField}) --This part said "Bad time format string".  

I tried IsTime and it said "A Time is required here."

Any ideas?

Thanks
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 100

Expert Comment

by:mlmcc
ID: 35233534
You need to replace YourTimeField with the name of your time field.
Same with YourDateField

mlmcc
0
 

Author Comment

by:LindaOKSTATE
ID: 35233659
I did do that before I ran it.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 35233906
Can any of the fields be NULL?

Are they all good time fields?

mlmcc
0
 

Author Comment

by:LindaOKSTATE
ID: 35234404
There are some null fields.  These may be removed with further record selection but there are some there now.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 35235666
Then you need to test for them.  NULL is not a valid time.

If you want the records with a NULL date or time then use
IsNull({YourDateField})
OR
IsNull({YourTimeField})
OR
DateTime(Date(Val(Left({YourDateField},4)), Val(Mid({YourDateField},5,2)), Val(Right({YourDateField},2)))+1,Time({YourTimeField})) >= CurrentDateTime

If you don't want those records then
Not IsNull({YourDateField})
AND
Not IsNull({YourTimeField})
AND
DateTime(Date(Val(Left({YourDateField},4)), Val(Mid({YourDateField},5,2)), Val(Right({YourDateField},2)))+1,Time({YourTimeField})) >= CurrentDateTime

mlmcc
0
 

Author Comment

by:LindaOKSTATE
ID: 35235783
The report starts to run and then I get the same error:

Time({table.time})  
bad time format string

0
 
LVL 100

Accepted Solution

by:
mlmcc earned 125 total points
ID: 35235989
Apparently you have a bad time field
You can try

Not IsNull({YourDateField})
AND
Not IsNull({YourTimeField})
AND
(
IsTime({YourTimeField}) AND
DateTime(Date(Val(Left({YourDateField},4)), Val(Mid({YourDateField},5,2)), Val(Right({YourDateField},2)))+1,Time({YourTimeField})) >= CurrentDateTime
)

mlmcc

0
 

Author Comment

by:LindaOKSTATE
ID: 35236338
That seemed to do the trick.  Thank you very much!

LindaOKState
0
 

Author Closing Comment

by:LindaOKSTATE
ID: 35236349
Very helpful, fast replies.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question