Jump to content

[SOLVED] function php like FROM_DAYS of mysql


prince198

Recommended Posts

ok

in my sql there two function

first is to_days()

so if i write

 

select to_days('2008-01-01')
i wil have result 733407

second function is from days

 

select from days (733407)

i wil have result 2008-01-01)

 

in php to have like function to_days i had to do this

<?php
$days = to_days("2008-01-01");

function to_days ($date)
{
    $days = round(strtotime($date) / (60 * 60 * 24)));
    return 719527 + $days;
}
and i will have 733407

but for from days i tried to reverse the operation

 

733407-719527/86400 

 

but i don't see how i get date in forme yyyy-mm-dd

 

i hpe you unterstand

 

 

[pre]

mysql> select TO_DAYS('1970-01-01');

+-----------------------+

| TO_DAYS('1970-01-01') |

+-----------------------+

|                719528 |

+-----------------------+[/pre]

 

therefore

 

<?php
function from_days ($d)
{
    $t = ($d - 719528) * 86400;
    return date ('Y-m-d', $t);
}

echo from_days(729669);                    // --> 1997-10-07
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.