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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date difference for date fields with different formats

Status
Not open for further replies.

ramc2000

Technical User
Nov 8, 2002
60
GT
I need to calculate the difference (in hours) between two dates, I know I can use the datediff function but I think both fields should be in exactly the same format. {field1} is a string and has the following format: "yymmddhhmm" and {field2} is a datetime: #yyyy, mm, dd, hh, mm, ss#

Am I right that both fields should be exactly in the same format for the datediff function to work? and if so, how should I convert {field1}?

Thank you all.
 
Try creating a formula to convert the date, and then use that formula in the datediff. Since you only have a 2 year precision for the year, I allowed for older dates:

if val(left(&quot;0201011159&quot;,2)) < 15 then
cdatetime(2000+val(left(&quot;0201011159&quot;,2)),val(mid(&quot;0201011159&quot;,3,2)),val(mid(&quot;0201011159&quot;,5,2)),val(mid(&quot;0201011159&quot;,7,2)),val(mid(&quot;0201011159&quot;,9,2)),0)
else
cdatetime(1900+val(left(&quot;0201011159&quot;,2)),val(mid(&quot;0201011159&quot;,3,2)),val(mid(&quot;0201011159&quot;,5,2)),val(mid(&quot;0201011159&quot;,7,2)),val(mid(&quot;0201011159&quot;,9,2)),0)

-k
 
Thank you, the formula works fine and it's a beautiful formula I might add.
 
Thank you, the formula works fine and it's a beautiful formula I might add.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top