{"id":22397,"date":"2018-06-06T18:15:07","date_gmt":"2018-06-06T11:15:07","guid":{"rendered":"http:\/\/tom.ji42.com\/?p=22397"},"modified":"2018-08-27T17:36:47","modified_gmt":"2018-08-27T10:36:47","slug":"how-can-i-subract-datetime-values","status":"publish","type":"post","link":"https:\/\/tom.tomwork.net\/?p=22397","title":{"rendered":"How Can I Subract DateTime Values?"},"content":{"rendered":"<p>VFP supports arithmetic on datetime values. When you substract one datetime from another you get the elapsed time in SECONDS.<\/p>\n<p align=\"left\">ie:<\/p>\n<p align=\"left\">datetime(2008,1,1,15,0,0) &#8211; datetime(2008,1,1,14,0,0) is 3600\u00a0<strong>SECONDS<\/strong>.<\/p>\n<p align=\"left\">However be carefull with datetime arithmetic and round the value to 0:<\/p>\n<div class=\"codeseg\">\n<div class=\"codecontent\">\n<div class=\"codesniptitle\">Code Snippet<\/div>\n<p>lnSeconds = round(m.ltEnd &#8211; m.ltStart, 0)<\/p>\n<\/div>\n<\/div>\n<p align=\"left\">And here is a little trick for formatting the result as time (in 24hr range):<\/p>\n<div class=\"codeseg\">\n<div class=\"codecontent\">\n<div class=\"codesniptitle\">Code Snippet<\/div>\n<p>? TRANSFORM(RIGHT(TTOC(CTOT(&#8216;0&#8242;)+(m.ltEnd &#8211; m.ltStart),1),6),&#8217;@R 99:99:99&#8217;)<\/p>\n<\/div>\n<div><!--more--><\/div>\n<div>\n<hr \/>\n<p>if you are using datetime fields then u can simply use<\/p>\n<p>higherDateTime &#8211; lowerDateTime<\/p>\n<p>it will give u result in milliseconds<\/p>\n<p>if you are using time fields then you have to extract hours, minutes (second is u r using)<br \/>\nfrom both the times and then find out the difference<\/p>\n<p>you can extract any part by using substr or left and right functions<br \/>\n(assuming seconds are off otherwise you need to modify following statements)<br \/>\nlcTime=TIME()<br \/>\nlnHour = val(LEFT(lcTime,2))<br \/>\nlnMinute = val(right(lcTime,2))<\/p>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<div><\/div>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>VFP supports arithmetic on datetime values. When you substract one datetime from another you get the elapsed time in SECONDS. ie: datetime(2008,1,1,15,0,0) &#8211; datetime(2008,1,1,14,0,0) is 3600\u00a0SECONDS. However be carefull with datetime arithmetic and round the value to 0: Code Snippet lnSeconds = round(m.ltEnd &#8211; m.ltStart, 0) And here is a little trick for formatting the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[13],"tags":[252,251,253],"class_list":["post-22397","post","type-post","status-publish","format-standard","hentry","category-13","tag-foxpro","tag-vfp","tag-visual-foxpro"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6cOVM-5Pf","_links":{"self":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts\/22397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=22397"}],"version-history":[{"count":2,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts\/22397\/revisions"}],"predecessor-version":[{"id":22399,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts\/22397\/revisions\/22399"}],"wp:attachment":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=22397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=22397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=22397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}