hoogie Posted February 12, 2008 Share Posted February 12, 2008 Hi, I'm having a strange problem formatting dates. I'm looping through an array of dates from a database. If I do it this way: <?php foreach ($date_array as $d) { echo date($d); } ?> I get a bunch of 2008-02-15s, which is the correct date. However, I only want the day number, so I write it like this: <?php foreach ($date_array as $d) { echo date("d", $d); } ?> This returns a bunch of 31s. Upon further investigation, I realized that when I try to format the date it returns December 31, 1969, no matter what my variable date is. I've done some google searching, and as far as I can tell I'm writing the code right, so I'm not sure what the problem is. I'm running XAMPP for Linux 1.6.5a PHP 5.2.5 MySQL 5.0.51 I have a feeling there is a simple answer to this question but I have been unable to find it. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/90623-simple-date-format-error/ Share on other sites More sharing options...
kenrbnsn Posted February 12, 2008 Share Posted February 12, 2008 The date() function wants to see a UNIX timestamp as the second parameter, not a string. You want to use something like: <?php foreach ($date_array as $d) { echo date("d", strtotime($d)).'<br>'; } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/90623-simple-date-format-error/#findComment-464594 Share on other sites More sharing options...
hoogie Posted February 12, 2008 Author Share Posted February 12, 2008 That was it. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/90623-simple-date-format-error/#findComment-464598 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.