Jump to content

PHP mysql time


Pain

Recommended Posts

Hi guys.

 

I want to make two records.

 

1)Current time and date.

2)Time and date after 20 seconds.

 

Now i have this piece of code:

<?php
$hr  = 0;
$min = 0;
$sec = 11;

echo $date = date("Y-m-d H:i:s");echo "\n";
echo $modified = time() + (0 * 0 * 0 * 20);

?>

 

I think there is something wrong with this line:

<?php
echo $modified = time() + (0 * 0 * 0 * 20);1
?>

I get something like this: 1324668576.

 

You can check this http://kingstonuni.atspace.co.uk/RPG/muziejus.php link to get a better view.

 

Any help would be appreciated. Thank you.

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/253764-php-mysql-time/
Share on other sites

time - "Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)."

 

The integer you're getting is actually correct in seconds.  If you're trying to store this in MySQL then why not use NOW() when inserting into the DB?

Link to comment
https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1300928
Share on other sites

Looks like that works, but the output is still in this format 1324670946.

I need it to be like this: 2011-12-23 20:08:46.

I think you're performing too many steps, something like this should suffice:

echo date('Y-m-d h:i:s', strtotime("+20 seconds"));

Link to comment
https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1300943
Share on other sites

Looks like that works, but the output is still in this format 1324670946.

I need it to be like this: 2011-12-23 20:08:46.

I think you're performing too many steps, something like this should suffice:

echo date('Y-m-d h:i:s', strtotime("+20 seconds"));

This is what i was searching for! Thank you!

Link to comment
https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1300949
Share on other sites

how can i retrieve timestamp from the db?:/

As Pikachu said, show us the code you're trying to use along with errors.  If you don't have code I would suggest Googling it, making an attempt, and coming back to specific help.  There are a multitude of good examples.

Link to comment
https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1301609
Share on other sites

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.