Need records for previous 24 hrs on demand, date and time combined in text filed

02/04/2010 06:44  This is a date-time combined field that is a string.  I need to be able to pull records for 24 hrs from demand time.  If possible, I would like to exclude nulls and times within the past 4 hrs of the demand.  For example, if I demand the report at 14:00 on March 30, I would like all the records from 14:00 March 29 up til 10:00 on March 30.

Thank you,
LindaOKState
LindaOKSTATEAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

James0628Commented:
Assuming that your "demand time" is going to be when the report is run, and assuming that your field will always contain a date and time in that format:

DateTime ({your datetime field}) in CurrentDateTime - 1 to DateAdd ("h", -4, CurrentDateTime)


 The "- 1" just subtracts 1 from the date.  The DateAdd subtracts 4 hours.

 If you want the user to select the date and time in a parameter, replace both instances of CurrentDateTime with your datetime parameter.

 James
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
musalmanERP ConsultantCommented:
IF you are looking for Last 24 Hours, Simply Put a Where Clause as:

Where DemandDate >= DATEADD("dd",-1,CONVERT(DATETIME,@DEMAND,120))
AND DATEADD("hh",-4,CONVERT(DATETIME,@DEMAND,120)) is not null


@Demand is your String Combined Field and DemandDate is your demand time Field.
0
LindaOKSTATEAuthor Commented:
musalman:
I am not sure what is meant by "your demand time Field"
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

James0628Commented:
Did you try my suggestion?  It would be entered in the record selection formula in CR, and should give you what you described.

 FWIW, for musalman's suggestion, DemandDate would be the name of the datetime string field that you mentioned (like {your datetime field} in my suggestion).  He appears to be assuming that you're using a stored procedure with a @DEMAND parameter that you use to pass it the "demand time", in a string form.  But I don't understand the second part, where it checks to see if @DEMAND - 4 hours is not null.  I don't see how it could be null (assuming that @DEMAND is a valid datetime), and there's no check to see if your datetime field is within the "- 4 hour" window.  Aside from that, I don't know if the CONVERT functions would work.  Normally you use a format like 120 to convert a datetime to a string, but he's trying to convert @DEMAND to a datetime.  And if @DEMAND is already a datetime (or maybe even a string that contains a date and time), then you don't need the CONVERT's at all.

 James
0
musalmanERP ConsultantCommented:
Definitely, I am assuming that he is using Sql Server SP, Hence, It is better to filter the records at database level but this is another story...

Conversion is required because he is concatenating the two string fields.

0
James0628Commented:
 musalman,

 Yes, it's better to filter the records on the server, but a formula like the one I posted should be passed to the server as part of the query for the report, so that shouldn't be a problem.

 And, FWIW, I don't see anything about concatenating fields.  The table field appears to be a string field with the date and time combined.  It was never really clear where the "demand time" was coming from (current date and time or user parameter or ...), but I see no reason to think that it was going to be in two strings.

 James
0
LindaOKSTATEAuthor Commented:
The date and time is one field formatted as text: 02/04/2010 06:44.  There is no demand parameter other than running the report (Current data and time) and thus the data is updated for the last 24 hrs (minus records for the most recent 4 hrs).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.