Jump to content



Recommended Posts

Well years ago i was told to use the int for the database field and the time() php statement.



database field int not null





$sql="insert into what_ever(date)values('$date')";



That will create a timestamp in unix..


format a time stamp use the date function


from a while loop




$date=date("h:i:s", data['date']);


now the time stamp only shows the time in hours min seconds



Link to comment
Share on other sites

I use INT(10) UNSIGNED for the database entry containing a timestamp and PHP's time() to populate it.

mysql_query("INSERT INTO `table` (`dt`) VALUES ('".time()."')");


When you get the date/time from the database you can display it using PHP's date() function:

echo date('d-M-Y H:i:s',$row['dt']);


See here for formatting the date and time:



The big thing I like about time() is sorting records can be done soooo easily and adding dates/times also as easy.


For example, to add 1 hour use this:

echo time()+(60*60);

Since time() is measured in seconds 60*60 is seconds*minutes which gives 3,600 - one hour.


btw, you use UNSIGNED for the MySQL database because time() is never negative and gives you the full range.

Link to comment
Share on other sites

Why not check then?


echo date("d-m-Y",strtotime("+4 years"));  //8-12-2008
echo "<br/>\n";
echo date("d-m-Y",time() + 4 * 365 * 24 * 3600);  //7-12-2008



strtotime wins again :P




I really don't understand, why you're saving dates as INT :P


Link to comment
Share on other sites


agree strtotime wins


$year = date('Y');

function isleapyear($year) {

   $year = (int) $year;
   if ($year % 4 == 0) {
      if ($year % 100 == 0) {
         return ($year % 400 == 0);
      } else {
         return true;
   } else {
      return false;
echo isleapyear($year);

Link to comment
Share on other sites

I have looked... but it doesn't completey tell me... cause in my database i have:




What can i do with that?


can you give me a wonderful prod please!?




Sorry Snoobs, as these guys have steered into their own thread.  The number you have is a timestamp.  You have to use the date function like so...


$your_date = 1228745009;
echo date("d-m-Y", $your_date));


Check out the manual - date() for more date formats.


Hope this is what you're looking for because I don't know what this means:


can you give me a wonderful prod please!?
Link to comment
Share on other sites

I find INT and time() so much more versatile than using the MySQL methods.


Even the forums use the INT time() method.


A matter of habit probably...

Just wanted our OP to know, there are other options :)

I can't imagine anything more convenient than TIMESTAMP DEFAULT CURRENT_TIMESTAMP :)


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.

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.