Sorry - need 4 digit year..
datediff("n", cdate(format(ppaddt,"0000/
Main Topics
Browse All TopicsI am not sure how to get started with this
DATEDIFF(PPADDT PPADTM, PPDSDT PPDSTM) ... I would like results to show when the difference is greater than 24 hours as well. (dd:hh:mm) or ex 40:mm)
PPADDT PPADTM PPDSDT PPDSTM
20091001 2310 20091002 450
20091001 2338 20091002 500
20091002 20 20091002 545
20091002 40 20091002 520
20091002 258 20091002 447
20091002 609 20091002 820
20091002 637 20091002 825
20091002 730 20091002 930
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
No, sorry, you can't use the Format function here. Format turns a date/time into a string - it cannot do the reverse!
I'm not clear whether your data is text or numeric, and this would make a difference to the approach. For example, to convert a string (s) in the form yyyymmdd to a date, you would use:
DateSerial( Left(s, 4), Mid(s, 5, 2), Right(s, 2) )
If the yyyymmdd was, say, a long integer (d) then you would use an arithmetic approach:
DateSerial( d \ 10000, (d \ 100) Mod 100, d Mod 100)
Looking at your time values, it looks like all your data is numeric - for example, 258 is presumably 2:58am and 20 is presumably 00:20, or 12:20am.
So, the first thing to do is write a function to take the date field and the time field and convert them into a date/time data type:
Public Function MakeDate( d as Long, t as Long) as Date
MakeDate = DateSerial( d \ 10000, (d \ 100) Mod 100, d Mod 100) _
+ TimeSerial( t \ 100, t Mod 100, 0 )
End Function
To find the difference between the two dates and times, use the smallest granularity in the source data for the unit - in this case, minutes:
DateDiff( "n", MakeDate(PPADDT, PPADTM), MakeDate(PPDSDT, PPDSTM) )
This will give you the difference, in minutes, between the two times.
To format this, once again you will need a custom function (the Format function is great for formatting points in time, but not durations). The following function will format a number of minutes as hh:mm, even if it is more than 24 hours:
Public Function MinsToHHMM( mins as Long ) as String
MinsToHHMM = mins \ 60 & ":" & Format( mins Mod 60, "00" )
End Function
Putting all this together, this should do the trick:
MinsToHHMM( DateDiff( "n", MakeDate(PPADDT, PPADTM), MakeDate(PPDSDT, PPDSTM) ) )
--
Graham
Hello Graham,
Format does in fact work, and I use this quite regularly. Peter's (modified) expression is:
DateDiff('n', Format([ppaddt],'0\-00\-00
Since Format() encounters a number format, it will, if needed, convert strings to numbers, and format them as numbers. This gives for example:
DateDiff('n', '2009-10-02 0:20', '2009-10-02 15:45')
DateDiff expects date/time parameters, and will convert them if needed. Since the strings are well-formed ISO dates, the conversion works.
I changed the format string slightly because '/' means "system date separator" (which can cause problems) and the space is my thousand separator (it needs to be escaped). Bottom line: escape all literals in format strings.
If PPADT is text, and if you want to avoid the implicit conversion to Long, you can format the string directly like this:
Format(PPADT, "@@@@-@@-@@")
If PPADT is a number it also works, but this time with an implicit conversion to string before the formatting...
Text formatting occurs left-to-right, so four '@' are needed. Number formatting occurs right-to-left, so Peter's first solution works just as well (on US computers).
Cheers!
(°v°)
Business Accounts
Answer for Membership
by: peter57rPosted on 2009-11-01 at 00:46:36ID: 25712930
The datediff expression is to give the difference in minutes is ..
/00 ") & format(ppadtm, "00:00")), cdate(format(ppdsdt,"00/00 /00 ") & format(ppdstm, "00:00")))
datediff("n", cdate(format(ppaddt,"00/00