dbTalk Databases Forums  

PHP MV date conversion script

comp.databases.pick comp.databases.pick


Discuss PHP MV date conversion script in the comp.databases.pick forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Matt Harting
 
Posts: n/a

Default PHP MV date conversion script - 02-09-2006 , 04:38 PM






Does someone have a PHP script that will do ICONV/OCONV of pick dates?
I have pulled some data from an MV box and have internal dates. I need
to OCONV to display and ICONV before writing them back.

Thanks.

Matt


Reply With Quote
  #2  
Old   
Mark Brown
 
Posts: n/a

Default Re: PHP MV date conversion script - 02-09-2006 , 05:32 PM






results = format(cDate(cSng(pickdate)+24837),"short date")

pickresults = cSng(inDate)-24837


or something equivalent.

There's 24837 days difference between Pick's date 0 and Windows.

Mark Brown


"Matt Harting" <mharting (AT) micahtek (DOT) com> wrote

Quote:
Does someone have a PHP script that will do ICONV/OCONV of pick dates?
I have pulled some data from an MV box and have internal dates. I need
to OCONV to display and ICONV before writing them back.

Thanks.

Matt




Reply With Quote
  #3  
Old   
Bruce A. Holt
 
Posts: n/a

Default Re: PHP MV date conversion script - 02-09-2006 , 05:40 PM




"Matt Harting" <mharting (AT) micahtek (DOT) com> wrote

Quote:
Does someone have a PHP script that will do ICONV/OCONV of pick dates?
I have pulled some data from an MV box and have internal dates. I need
to OCONV to display and ICONV before writing them back.

Thanks.

Matt

Tell ya what, I'll tell you how and YOU make the script.

PHP bases dates on the date of the Unix Epoch (01/01/1970). Somewhat like
MV, this date can be represented in a numeric string but unlike MV, this
string is the number of seconds since 01/01/1970 whereas MV uses the number
of days since 12/31/1967.

So, there is a difference of 732 days between the two dates (date 0 in PHP
would be date 732 in MV). Therefore, you would take the MV date and subtract
732. Next, you have to convert this number to seconds. there are 86400
seconds in a day. Multiply the result above by 86400 and you have your
numeric string that represents your date in PHP. Example:

MV date for 02/09/2006 = 13920
(13920 - 732) * 86400 = 1139443200

Now, use the strtotime function to convert that to a date in PHP

Going the reverse direction, use the mktime function to convert the date you
want converted to the numeric representation of seconds since 01/01/1970.
Reverse the calculation above ((1139443200 / 86400) + 732 = 13920) and you
have your MV date in internal format.

HTH

-Bruce




Reply With Quote
  #4  
Old   
Matt Harting
 
Posts: n/a

Default Re: PHP MV date conversion script - 02-09-2006 , 05:48 PM



Thanks Bruce.

That was what I was looking for.

Matt


Reply With Quote
  #5  
Old   
Bruce A. Holt
 
Posts: n/a

Default Re: PHP MV date conversion script - 02-10-2006 , 11:16 AM




"Matt Harting" <mharting (AT) micahtek (DOT) com> wrote

Quote:
Thanks Bruce.

That was what I was looking for.

Matt

Glad I could help! See? I'm not *just* a frivolous poster *all* the time!

*grins*

-Bruce




Reply With Quote
  #6  
Old   
Matt Harting
 
Posts: n/a

Default Re: PHP MV date conversion script - 02-13-2006 , 10:38 AM



Here are the actual PHP functions I wrote in case anyone else needs
them. I am not sure why on the output conversion I had to use 731
instead of 732 for the number of days, but I think it has something to
do with the time portion and how it handles midnight.

function DateOconv($idate, $format="m/d/Y")
{
// take Pick internal date and output in external format
// first convert internal date to timestamp
// time stamp is number of seconds from Jan 1, 1970
// Pick internal date is num days from 12/31/1967 (12/31/1967=0,
1/1/1968=1)
$timestamp= ($idate - 731) * 86400;
return (date($format, $timestamp));
}

function DateIconv($datestring)
{
// convert incoming date string to Pick internal date
// assumes incoming date string is in format of MM/DD/YYYY
$aDate=explode('/',$datestring);
$timestamp=mktime(0,0,0,$aDate[0],$aDate[1],$aDate[2]);
return (floor($timestamp/86400)+732);
}

Matt


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.