Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculate days between different da

Status
Not open for further replies.

tongw

Programmer
Oct 20, 2016
9
0
0
US
calculate days between different date and time:

Please help me if anything wrong here:

Problem is here: e.g, test_dt=3/22/2017, test_tm=10:50:00; dx_dt=3/24/2017, dx_tm=9:45:00 but the result is 3.00 (days) not 2.96(days)


if( dx_tm>=test_tm, (daysafter( test_dt, dx_dt )) + ((secondsafter(test_tm, dx_tm)/3600))/24, ((daysafter( test_dt, dx_dt )) + (1-abs(secondsafter(test_tm, dx_tm)/3600))/24))


Appreciate your help!!
 
I suggest you test your expression by adding some temp columns to separate the time and day components to make sure the pieces are being evaluated properly.

Matt

"Nature forges everything on the anvil of time"
 
Try converting the DaysAfter between the dates to seconds by multiplying it by 86400, then add the
SecondsAfter between the time, then convert the result back to days by dividing it by 86400. For example:

ldec_days = ((DaysAfter(test_dt, dx_dt) * 86400) + SecondsAfter(test_tm, dx_tm)) / 86400
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top