Jump to content

convertion dates


Jay2391

Recommended Posts

well i know how to do that .... but i need to do it in seconds first....why bacause what i am trying to do is set up a time with in 24hrs of the original time and have a auto counter that will keep track....

 

so with dates i can't figure out but with seconds i can do it really easy...

 

so the question is can i convert that number into a actual date format????

Link to comment
Share on other sites

why is my date not giving the correct info...

 

 

///////////I set up a static time and add one full day

$rt = 1173128934 + 86400;

 

///////////////i get todays date

$ut = date('U');

 

////////////////i substract todays date to the static time and try to get the difference

$tbthere = $rt - $ut;

 

 

//////////////I convert and echo

 

 

//////////i get the correct time

echo date('Y-m-d / H:m',$ut);

echo "<br>";

////////////i get the correct time

echo date('Y-m-d / H:m',$rt);

echo "<br>";

 

Incorrect time ???? why is that ????

echo date('H:m',$tbthere);

Link to comment
Share on other sites

The reason it is not displaying what you want is that the second argument for the date() function is an integer representing the number of seconds since 1-1-1970. What you are passing it is a number representing the number of second between two times. BTW, the format string you're using, "H:m", does not print hours & minutes. The "m" is for the number of the current month, you want to use the "i" to get minutes -- "H:i".

 

One solution to your problem would be to get the the number of seconds since 1-1-1970 of any date at midnight, add your value to it and format that number as "H:i":

<?php
///////////I set up a static time and add one full day
$rt = 1173128934 + 86400;

///////////////i get todays date
$ut = date('U');

////////////////i substract todays date to the static time and try to get the difference
$tbthere = $rt - $ut;


//////////////I convert and echo


//////////i get the correct time
echo date('Y-m-d / H:i',$ut) . '<br>';

////////////i get the correct time
echo date('Y-m-d / H:i',$rt) . '<br>';

// Echo the correct formatted difference
echo date('H:i',strtotime('3/3/2007 00:00') + $tbthere) . '<br>';
?>

 

Ken

Link to comment
Share on other sites

May be i miss read something I see that it dosen't really work

 

2007-03-06 / 12:14  correct  current time

2007-03-07 / 16:08  day and time expiration

03:54    ---this should be  27:54 because this is how many hours to reach the exp date and time

 

I know you mention about getting a time at midnight ....

 

strtotime('3/3/2007 00:00')

 

but you did that already .... so what do you mean another substraction then ???

Link to comment
Share on other sites

My method only works if the difference is less than a day.

 

As a general method, try this:

<?php
$diff_hours = floor($tbthere / 3600);
$diff_mins = floor($tbthere % 3600)/60;
echo sprintf("<br>%02d:%02d",$diff_hours,$diff_mins);
?>

 

Ken

Link to comment
Share on other sites

my plan is to alway be less than a day but the extra info and code didn't hurt .... thanks that work not quite sure how you  did it

but it works, I willl take a closer look at the code and try to understand i hate when I am all confuse, LOL  ..Thanks Again!!!!

Link to comment
Share on other sites

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.