chocopi Posted May 20, 2007 Share Posted May 20, 2007 What is the best way to store dates into database so the data can be retrieved later on. For example: I use this to get the date and i store it. <?php $date = date('d/m/y'); ?> However, if i wanted it to say '20 March 2007' would this be easy or is there a better way to store them. Cheers, ~ Chocopi Link to comment https://forums.phpfreaks.com/topic/52234-dates-in-database-retrieving/ Share on other sites More sharing options...
MadTechie Posted May 20, 2007 Share Posted May 20, 2007 well i use TIME(); but everyone has their own way! <?php $nextWeek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs echo 'Now: '. date('Y-m-d') ."\n"; echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n"; // or using strtotime(): echo 'Next Week: '. date('Y-m-d', strtotime('+1 week')) ."\n"; ?> Link to comment https://forums.phpfreaks.com/topic/52234-dates-in-database-retrieving/#findComment-257679 Share on other sites More sharing options...
chocopi Posted May 20, 2007 Author Share Posted May 20, 2007 Is there an advantage of using time() over date() as i only used date as it seemed the most obvious Link to comment https://forums.phpfreaks.com/topic/52234-dates-in-database-retrieving/#findComment-257683 Share on other sites More sharing options...
spfoonnewb Posted May 20, 2007 Share Posted May 20, 2007 --Ignore-- Link to comment https://forums.phpfreaks.com/topic/52234-dates-in-database-retrieving/#findComment-257688 Share on other sites More sharing options...
chocopi Posted May 20, 2007 Author Share Posted May 20, 2007 Cheers for that Anyways, can you help with an array so when i have 20/05/2007 it says 20 May 2007 would it be like: <?php $month = array('','January','February','March','April','May','June','July','August','September','October','November','December'); while($row = mysql_fetch_assoc($date)) { $mon = $month[$row['date']]; echo "The month is $mon\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/52234-dates-in-database-retrieving/#findComment-257700 Share on other sites More sharing options...
Barand Posted May 20, 2007 Share Posted May 20, 2007 Closing this post as you asked the same question (near as dammit, anyway) in another post - please don't double post. Link to comment https://forums.phpfreaks.com/topic/52234-dates-in-database-retrieving/#findComment-257812 Share on other sites More sharing options...
Recommended Posts