Solved

Previous day date time end of day

Posted on 2011-03-11
13
576 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
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.

 
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

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

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…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

24 Experts available now in Live!

Get 1:1 Help Now