Solved

Pull records from last 24 hours in Crystal Reports

Posted on 2011-03-25
12
1,684 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 100

Expert Comment

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

mlmcc
0
 

Author Comment

by:LindaOKSTATE
Comment Utility
I did do that before I ran it.
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Can any of the fields be NULL?

Are they all good time fields?

mlmcc
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:LindaOKSTATE
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
That seemed to do the trick.  Thank you very much!

LindaOKState
0
 

Author Closing Comment

by:LindaOKSTATE
Comment Utility
Very helpful, fast replies.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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. …
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 …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now