Jump to content

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
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.