refiking Posted November 2, 2009 Share Posted November 2, 2009 I had a function that worked perfectly when I stored the timestamp version of time (all digits) in the db. But, I changed it from varchar to date and have had problems with this function since. Can you tell me what is wrong with it? Here is the version that worked before I changed the db: function getDatetoArray() { $today = getdate(); $firstDay = mktime(0,0,0,$today['mon'],1,$today['year']); $lastDay = mktime(0,0,0,$today['mon']+1,0,$today['year']); $sql = mysql_query("Select date from agenda where date>'".$firstDay."' and date<'".$lastDay."'"); $datearray = array(); while($row = mysql_fetch_array($sql)) { $date = getdate($row['date']); $datearray[] = $date['mday']; } return $datearray; } And here is the version that I am trying to fix now that doesn't work.. function getDatetoArray() { $today = getdate(); $firstDay = date("Y-m-d", mktime(0,0,0,$today['mon'],1,$today['year'])); $lastDay = date("Y-m-d", mktime(0,0,0,$today['mon']+1,0,$today['year'])); $sql = mysql_query("Select date from agenda where date>'".$firstDay."' and date<'".$lastDay."'"); $datearray = array(); while($row = mysql_fetch_array($sql)) { $date = time($row['date']); $datearray[] = $date['mday']; } return $datearray; } Link to comment https://forums.phpfreaks.com/topic/179928-having-trouble-with-a-date-function/ Share on other sites More sharing options...
refiking Posted November 2, 2009 Author Share Posted November 2, 2009 Ok. So, instead of trying to convert the function, I just added another db field named date_reformatted and the function works again, but it didn't pull all of the entries like it was supposed to. It was supposed to retrieve 3 records, but it only retrieved 2. If I set the order to search by date or date_reformatted, the last 2 show up. If I set it to desc, the first 2 show up. Please help here gurus... function getDatetoArray() { $today = getdate(); $firstDay = mktime(0,0,0,$today['mon'],1,$today['year']); $lastDay = mktime(0,0,0,$today['mon']+1,0,$today['year']); $sql = mysql_query("Select date_reformatted from agenda where date_reformatted>'".$firstDay."' and date_reformatted<'".$lastDay."'"); $datearray = array(); while($row = mysql_fetch_array($sql)) { $date = getdate($row['date_reformatted']); $datearray[] = $date['mday']; } return $datearray; } Link to comment https://forums.phpfreaks.com/topic/179928-having-trouble-with-a-date-function/#findComment-949170 Share on other sites More sharing options...
refiking Posted November 2, 2009 Author Share Posted November 2, 2009 I also just ran this and it returned the number 3. $sql = mysql_query("Select date_reformatted from agenda where date_reformatted>'".$firstDay."' and date_reformatted<'".$lastDay."' order by date_reformatted desc"); echo mysql_num_rows($sql); Link to comment https://forums.phpfreaks.com/topic/179928-having-trouble-with-a-date-function/#findComment-949172 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.