{"id":1843,"date":"2009-02-20T23:13:30","date_gmt":"2009-02-20T23:13:30","guid":{"rendered":"http:\/\/www.amibroker.org\/userkb\/?p=1843"},"modified":"2009-02-20T23:13:30","modified_gmt":"2009-02-20T23:13:30","slug":"date-and-time-to-number-conversions","status":"publish","type":"post","link":"http:\/\/www.amibroker.org\/editable_userkb\/2009\/02\/20\/date-and-time-to-number-conversions\/","title":{"rendered":"Date and Time to Number Conversions"},"content":{"rendered":"
Code developed and kindly donated by Murthy Suresh.<\/p>\n
<\/span>{\r <\/span>dd_ <\/span>= <\/span>StrToNum<\/span>( <\/span>StrRight<\/span>( <\/span>aaaammdd<\/span>, <\/span>2 <\/span>) ); <\/span>\/\/printf(WriteVal(dd_) + " " );\r <\/span>mm_ <\/span>= <\/span>StrToNum<\/span>( <\/span>StrMid<\/span>( <\/span>aaaammdd<\/span>, <\/span>4<\/span>, <\/span>2 <\/span>) ); <\/span>\/\/printf(WriteVal(mm_) + " " );\r <\/span>aa_ <\/span>= <\/span>StrToNum<\/span>( <\/span>StrLeft<\/span>( <\/span>aaaammdd<\/span>, <\/span>4 <\/span>) ); <\/span>\/\/printf(WriteVal(aa_) + " " + \"\\n" );\r <\/span>Date_Num <\/span>= ( <\/span>10000 <\/span>* ( <\/span>aa_ <\/span>- <\/span>1900 <\/span>) ) + ( <\/span>100 <\/span>* <\/span>mm_ <\/span>) + <\/span>dd_<\/span>;\r <\/span>RESULT <\/span>= <\/span>Date_Num<\/span>;\r return <\/span>RESULT<\/span>;\r}\r\rfunction <\/span>Time_To_Num<\/span>( <\/span>strTime <\/span>) <\/span>\/\/ format for time is hh:mm:ss\r<\/span>{\r <\/span>\/*\r \/\/do something to raise alert if length does not match\r ????PopupWindow(\"Current time is: " + Now(),\"Alert\", 2,\r 640*mtRandom(), 480*mtRandom());\r *\/\r <\/span>hh_t <\/span>= <\/span>StrToNum<\/span>( <\/span>StrLeft<\/span>( <\/span>strTime<\/span>, <\/span>2 <\/span>) ); <\/span>\/\/printf(WriteVal( hh_t ) + " " );\r <\/span>mm_t <\/span>= <\/span>StrToNum<\/span>( <\/span>StrMid<\/span>( <\/span>strTime<\/span>, <\/span>3<\/span>, <\/span>2 <\/span>) ); <\/span>\/\/printf(WriteVal( mm_t ) + " " );\r <\/span>ss_t <\/span>= <\/span>StrToNum<\/span>( <\/span>StrRight<\/span>( <\/span>strTime<\/span>, <\/span>2 <\/span>) ); <\/span>\/\/printf(WriteVal( ss_t ) + " " + \"\\n" );\r <\/span>Time_Num <\/span>= <\/span>10000 <\/span>* <\/span>hh_t <\/span>+ <\/span>100 <\/span>* <\/span>mm_t <\/span>+ <\/span>ss_t<\/span>;\r <\/span>RESULT <\/span>= <\/span>Time_Num<\/span>;\r return <\/span>RESULT<\/span>;<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"Code developed and kindly donated by Murthy Suresh. { dd_ = StrToNum( StrRight( aaaammdd, 2 ) ); \/\/printf(WriteVal(dd_) + " " ); mm_ = StrToNum( StrMid( aaaammdd, 4, 2 ) ); \/\/printf(WriteVal(mm_) + " " ); aa_ = StrToNum( StrLeft( aaaammdd, 4 ) ); \/\/printf(WriteVal(aa_) + " " + “\\n" ); Date_Num = ( 10000 * ( aa_ – 1900 ) ) + ( 100 * mm_ ) + dd_; RESULT = Date_Num; return RESULT; } function Time_To_Num( strTime ) \/\/ format for time is hh:mm:ss { \/* \/\/do something to raise alert if length does not match ????PopupWindow(“Current time is: " + Now(),”Alert”, 2, 640*mtRandom(), 480*mtRandom()); *\/ hh_t = StrToNum( StrLeft( strTime, 2 ) ); \/\/printf(WriteVal( hh_t ) + " " ); mm_t = StrToNum( StrMid( strTime, 3, 2 ) ); \/\/printf(WriteVal( mm_t ) + " " ); ss_t = StrToNum( StrRight( strTime, 2 ) ); \/\/printf(WriteVal( ss_t ) + " " + “\\n" ); Time_Num = 10000 * hh_t + 100 * mm_t + ss_t; RESULT = Time_Num; return RESULT;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[78,1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/1843"}],"collection":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/comments?post=1843"}],"version-history":[{"count":0,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/1843\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/media?parent=1843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/categories?post=1843"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/tags?post=1843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}