[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
Solved

Previous day date time end of day

Posted on 2011-03-11
Medium Priority
593 Views
I am trying to calculate the difference/duration for a previuos day time using the previous day 'end of day' as my refference, see the example below : (time to date and duration from date to end of day)

value (DateTime) 10/3/2011  11:27:31PM and I want to calculate  the duration from this time until the end of day 10/3/2011 23:59:59PM and then also the time from midnight (10/3/2011 00:00:00 to 10/3/2011 11:27:31pm)

Keep in mind that this report will be done on the following day (11/3/2011) and access a .txt file with data from the previous day (10/3/2011).
0
Question by:John-S Pretorius
• 7
• 4
• 2

LVL 101

Accepted Solution

mlmcc earned 420 total points
ID: 35113874
Try this idea
Name - TimeTillEndOfDay
Local DateTimeVar YesterdayEnd := DateTime(CurrentDate,Time(23,59,59));
Time(DateDiff('s',{YourDateTimeField},YesterdayEnd ));

Name - TimeSinceStartOfDay
Local DateTimeVar YesterdayStart := DateTime(CurrentDate,Time(0,0,0));
Time(DateDiff('s',YesterdayStart ,{YourDateTimeField}));

mlmcc

0

Author Comment

ID: 35113978
parc.txt Galthouse-PARC-NewReport.rpt

I'm getting a 12:00:00 am when placing either formula, attatched find my current work. What I'm trying to accomplish is to detemine if exit then determine time from start of day to exit time and when entry : entry time to end of day.

When I have the duration of each I can create a true revenue for only time spend inside.
0

LVL 101

Expert Comment

ID: 35114560
How do you determine exit or entry?

Is this dumped each day so you don't have entry time from the previous day or exit time from the next day?

mlmcc
0

Author Comment

ID: 35114573
Yes it is dumped each day, just for that specific day. I have been scratching on this all day, if it is an entry {Device #} = 51 and 52 and for a exit it will be 54 and 55.

if it is an entry (System device designation - ENT ) then duration should be from that time to end of day and if it is an exit then (System device designation - EX) duration should be from midnight to that time.

It seems that it will be easier to work with duration rather than datetime since it's always for only 1 day.
0

LVL 101

Expert Comment

ID: 35114684
Duration on exit is just the time

Duration on enter is as above.

What about entries that have the same serial number does that matter or are you selecting just those with a single entry /exit for the day?

mlmcc
0

Author Comment

ID: 35114692
I am grouping by serial number and sorting by time (descending) which means it will always use the latest time.

At this stage I'm lucky and only have to deal with one timestamp per serial number, this may change should the same serial number entry and exit within the same day (%5 change of that hapening) but for now I just want to figure duration from midnight and duration to end of day.

This will improve the 'truth' of the actual revenue to at least 90% accurate which I can play with. When this part is figured I can start looking at should there be more than one transaction/serial number.

The goal is to show the revenue that would have been collected if the user(serial#) was actually present within the garage.

I really do appreciate your assistance.
0

LVL 35

Assisted Solution

James0628 earned 80 total points
ID: 35115505
The basic calculations are pretty simple.  Assuming {datefield} is the name of your datetime field.

The number of seconds in the day before {datefield}:

DateDiff ("s", DateTime (Date ({datefield})), {datefield})

The number of seconds in the day after {datefield}:

DateDiff ("s", {datefield}, DateTime (Date ({datefield}), Time ("11:59:59 PM")))

Technically, those give you the number of seconds in the day _before_ and _after_ the given time.  They don't include that second.  If you add the results from those two formulas together, you should get 86399 (the number of seconds in a day, 86400, minus 1).  You can add 1 to either formula to add that second if you like.

James
0

Assisted Solution

John-S Pretorius earned 0 total points
ID: 35115516
Guys,

Thank you so much for all the assistance, I have figured it out and will leave you with a copy of the report and data file. Worked out pretty sweet but you would notice when you should open my formula's that I'm still new at Crystal. I am most probably over doing some step but believe I can learn over time to be good at it.

Thanks again,

johnsp1234 parc.txt Galthouse-PARC-NewReport.rpt
0

Author Comment

ID: 35115520
Thank you all
0

LVL 35

Expert Comment

ID: 35115552
FWIW, I looked at the report briefly and there are some things that don't seem necessary.

{@extract_date} extracts a datetime string from SerialNo#.

{@Convert date string} converts {@extract_date} into a datetime.

{@Convert2} then extracts the month, day, year and time from {@Convert date string} and just puts them back together, giving you the same datetime value again.  I don't see any point in that.  Wherever you used {@Convert2}, like in {@duration}, you could just use {@Convert date string} instead.

FWIW, I would also combine {@extract_date} and {@Convert date string} into one formula.  Having to go from formula A to formula B to formula C just to see what's going on, especially when the formulas are only a line or two, just seems overly complicated to me, assuming that you don't need the intervening values for something else (like to show on the report).  And in this case if you did happen to need a "date string" like the value in {@extract_date}, you could presumably just use the datetime value and format it the way you want on the report, or convert it to a string in a formula.

James
0

Author Comment

ID: 35115584
Thank you for the feedback James, I will keep learning these things everyday. Please have a look at another 2 open problems I'm struggling with, maybe your experies can come in handy and solve them.

Have a good one, hope to hear from you.
0

LVL 101

Expert Comment

ID: 35116642
James - could you take a look at this question.  He wants to repeat different headers if a group goes to a second page.
http://www.experts-exchange.com/Database/Reporting_/Crystal_Reports/Q_26875282.html?cid=1572#a35115931

mlmcc
0

Author Closing Comment

ID: 35154444
The guys helped allot an I managed to complete the report.
0

Featured Post

Question has a verified solution.

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

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 â€¦
Integration Management Part 2
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can eâ€¦
Suggested Courses
Course of the Month17 days, 21 hours left to enroll