Pain Posted December 23, 2011 Share Posted December 23, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253764-php-mysql-time/ Share on other sites More sharing options...
Pain Posted December 23, 2011 Author Share Posted December 23, 2011 Sorry, please ignore this peace of code. <?php ... $hr = 0; $min = 0; $sec = 11; ... ?> Quote Link to comment https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1300926 Share on other sites More sharing options...
Maq Posted December 23, 2011 Share Posted December 23, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1300928 Share on other sites More sharing options...
Pikachu2000 Posted December 23, 2011 Share Posted December 23, 2011 Any value multiplied by zero results in zero, so your ( 0 * 0 * 0 * 20 ) is cratering the addition. $now = time(); $time_in_20_seconds = $now + 20; Quote Link to comment https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1300929 Share on other sites More sharing options...
Pain Posted December 23, 2011 Author Share Posted December 23, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1300941 Share on other sites More sharing options...
Pikachu2000 Posted December 23, 2011 Share Posted December 23, 2011 Use date to format it. If it's going into a database record, read Maq's post above. Quote Link to comment https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1300942 Share on other sites More sharing options...
Maq Posted December 23, 2011 Share Posted December 23, 2011 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")); Quote Link to comment https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1300943 Share on other sites More sharing options...
Pain Posted December 23, 2011 Author Share Posted December 23, 2011 Yes i want to put two records into the database. Not sure how to do this. Sorry im really bad at this date and time thing. Quote Link to comment https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1300946 Share on other sites More sharing options...
Pain Posted December 23, 2011 Author Share Posted December 23, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1300949 Share on other sites More sharing options...
Maq Posted December 23, 2011 Share Posted December 23, 2011 If you're storing dates in a DB then you probably want to store it as a TIMESTAMP. That way you can operate on it if need be (get a certain range, add, subtract etc.). Quote Link to comment https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1300961 Share on other sites More sharing options...
Pain Posted December 23, 2011 Author Share Posted December 23, 2011 Yes i have stored them as timestamps, but now im having some difficulties trying to display them. I guess it's not the same as retrieving INT or VARCHAR? Quote Link to comment https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1300962 Share on other sites More sharing options...
Pain Posted December 23, 2011 Author Share Posted December 23, 2011 how can i retrieve timestamp from the db?:/ Quote Link to comment https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1300980 Share on other sites More sharing options...
Pikachu2000 Posted December 23, 2011 Share Posted December 23, 2011 Don't bump threads. What problems are you having, specifically. Post the code that's causing the current problems as well. Quote Link to comment https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1300981 Share on other sites More sharing options...
Maq Posted December 27, 2011 Share Posted December 27, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253764-php-mysql-time/#findComment-1301609 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.