refiking Posted April 1, 2008 Share Posted April 1, 2008 I have a countdown applet that requires I seperate each value from the date stored in the DB. How can I seperate these values correctly. When I tried it, it gave me the following result: 1969 12 31 07 33 28 Here is my current code as is: <?php $lid = 1; $sid = 21; include 'cont.php'; $sql = mysql_query("SELECT * FROM dlg WHERE lid = '$lid' AND sid = '$sid' LIMIT 1"); while($row = mysql_fetch_array($sql)){ $newdate = $row['dtime']; } $year = date('Y', $newdate); $month = date('m', $newdate); $day = date('d', $newdate); $minute = date('i', $newdate); $hour = date('h', $newdate); $second = date('s', $newdate); echo $year."<br>".$month."<br>".$day."<br>".$hour."<br>".$minute."<br>".$second; ?> Link to comment https://forums.phpfreaks.com/topic/99046-coding-a-date-from-db/ Share on other sites More sharing options...
trq Posted April 1, 2008 Share Posted April 1, 2008 How can I seperate these values correctly. How exactly do you want them seperated? Your code and description doesn't actually describe your problem very well. Link to comment https://forums.phpfreaks.com/topic/99046-coding-a-date-from-db/#findComment-506820 Share on other sites More sharing options...
refiking Posted April 1, 2008 Author Share Posted April 1, 2008 I need a year, month, day, hour, minute, and second value. For example, if the DB records shows this: 2008-04-01 16:45:37 I need it to return this: $year = 2008 $month = 4 $day = 1 $hour = 16 $minute = 45 $second = 37 Link to comment https://forums.phpfreaks.com/topic/99046-coding-a-date-from-db/#findComment-506823 Share on other sites More sharing options...
trq Posted April 1, 2008 Share Posted April 1, 2008 You just described your code as doing that. What is the problem? Link to comment https://forums.phpfreaks.com/topic/99046-coding-a-date-from-db/#findComment-506835 Share on other sites More sharing options...
refiking Posted April 1, 2008 Author Share Posted April 1, 2008 It didn't return the value from the record. It returned this: 1969 12 31 07 33 28 Link to comment https://forums.phpfreaks.com/topic/99046-coding-a-date-from-db/#findComment-506838 Share on other sites More sharing options...
trq Posted April 1, 2008 Share Posted April 1, 2008 How was I to know thats not what was in your record? What field type is dtime? Link to comment https://forums.phpfreaks.com/topic/99046-coding-a-date-from-db/#findComment-506841 Share on other sites More sharing options...
refiking Posted April 1, 2008 Author Share Posted April 1, 2008 it is datetime Link to comment https://forums.phpfreaks.com/topic/99046-coding-a-date-from-db/#findComment-506844 Share on other sites More sharing options...
trq Posted April 1, 2008 Share Posted April 1, 2008 You'll need to use strtotime(). <?php $year = date('Y', strtotime($newdate)); ?> Link to comment https://forums.phpfreaks.com/topic/99046-coding-a-date-from-db/#findComment-506857 Share on other sites More sharing options...
refiking Posted April 1, 2008 Author Share Posted April 1, 2008 It Worked! Thanks! Link to comment https://forums.phpfreaks.com/topic/99046-coding-a-date-from-db/#findComment-506862 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.