Solved

Pull records from last 24 hours in Crystal Reports

Posted on 2011-03-25
12
1,713 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Converting int to currency 5 31
across tab - Distinct Count - Crystal Reports 2 76
Dynamic Image won't display if no data is returned 11 50
Mask on Parameter CR2008 28 43
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

912 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

17 Experts available now in Live!

Get 1:1 Help Now