Solved

Pull records from last 24 hours in Crystal Reports

Posted on 2011-03-25
12
1,775 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
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …

685 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