Solved

Help with Formula

Posted on 2011-03-17
8
223 Views
Last Modified: 2012-05-11
Hi,

I have a field called UTIMEOD which contains date and time in the following format.  The field captures what date and time the record was submitted to our website.

2011-03-17 10:15:00

Im trying to write a report which identifies records which are submitted between midnight and midday and also between midday and midnight.

What would be the syntax to query this field and allow me to pick up the records base on the time frame?
0
Comment
Question by:daiwhyte
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 77

Expert Comment

by:peter57r
Comment Utility
You can get two groups just by testing the hour.

If Hour({table.datetimefield} <12 then
""Group1"
else
"Group2"


You can then group the report on date and/or group.
To get the date on its own you can do
Datevalue({table.datetimefield})
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Is the field a datetime or string field?

If string how does it show PM times?

mlmcc
0
 

Author Comment

by:daiwhyte
Comment Utility
Its a string field and it uses the 24hr clock.
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 250 total points
Comment Utility
Try this.  You can change the result to whatever words or value you want

If Mid({YourStringField},12,2) < 12 then
   "Morning"
Else
   "Afternoon"

mlmcc
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 34

Assisted Solution

by:James0628
James0628 earned 250 total points
Comment Utility
You need to change the first line of mlmcc's formula, because it's trying to compare a string (Mid) to a number (12).  But how you change it may depend on the format of the time in your field.  Does the hour have a leading 0 or space?  For example, would 8 AM be

2011-03-17 08:00:00
 or
2011-03-17  8:00:00    (with an extra space in front of the 8)
 or
2011-03-17 8:00:00

 If it has a leading 0 or space, you can just make 12 a string:

If Mid({YourStringField},12,2) < "12" then

 If it doesn't have a leading 0 or space, then a string comparison won't work, but converting the hour to a number probably will:

If Val (Mid({YourStringField},12,2)) < 12 then


 Technically, Val would also work if the hours included a leading 0 or space.  It's just not necessary in that case.

 James
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
An even better way to test the hour would be this since there is no need to worry on the exact format

if Val(Split(Split({YourStringField},' ')[2],':')[1]) < 12 then
   "Morning"
Else
   "Afternoon"

mlmcc

0
 

Author Closing Comment

by:daiwhyte
Comment Utility
Thank you both, this was a great help and the problem is now solved.
0
 
LVL 34

Expert Comment

by:James0628
Comment Utility
You're welcome.  Glad I could help.

 James
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

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

11 Experts available now in Live!

Get 1:1 Help Now