Solved

Previous day date time end of day

Posted on 2011-03-11
13
575 Views
Last Modified: 2012-05-11
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
Comment
Question by:John-S Pretorius
  • 7
  • 4
  • 2
13 Comments
 
LVL 100

Accepted Solution

by:
mlmcc earned 105 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

by:John-S Pretorius
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 100

Expert Comment

by:mlmcc
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

by:John-S Pretorius
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 100

Expert Comment

by:mlmcc
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

by:John-S Pretorius
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 34

Assisted Solution

by:James0628
James0628 earned 20 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

by:John-S Pretorius
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 Image
0
 

Author Comment

by:John-S Pretorius
ID: 35115520
Thank you all
0
 
LVL 34

Expert Comment

by:James0628
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

by:John-S Pretorius
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 100

Expert Comment

by:mlmcc
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

by:John-S Pretorius
ID: 35154444
The guys helped allot an I managed to complete the report.
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

Suggested Solutions

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. …
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

12 Experts available now in Live!

Get 1:1 Help Now