scottrohe Posted August 5, 2006 Share Posted August 5, 2006 Ok well I have everything right I just need to know WHICH date format I should use when entering the date into the db.ex; I've tried:[code=php:0]<?php $date = date('dmy', strtotime($date));?>[/code]so I get the result of '050806' but when I order that in a sql queue 'ORDER BY date DESC', and i test it by changing the date around on tables, it just doesn't work flawlessly. I was also wanting to add in like a timestamp so if 2 items are added at once, but one is added a second or two later, it's newer and therefore displays ahead of the one added 2 seconds before it.. what would my 'date' variable be? Thanks. Link to comment https://forums.phpfreaks.com/topic/16670-order-by-date-display-newest-item/ Share on other sites More sharing options...
Barand Posted August 5, 2006 Share Posted August 5, 2006 Best is 2006-08-06 (Y-m-d) so it is sortableIf you make it a DATETIME type and store the value NOW() into it when you add a record then you will get Y-m-d H:i:s Link to comment https://forums.phpfreaks.com/topic/16670-order-by-date-display-newest-item/#findComment-69991 Share on other sites More sharing options...
nethnet Posted August 5, 2006 Share Posted August 5, 2006 Insert them with the MySQL function now(). That inputs a timestamp. You can always format it when you retrieve it from the database. Link to comment https://forums.phpfreaks.com/topic/16670-order-by-date-display-newest-item/#findComment-69992 Share on other sites More sharing options...
scottrohe Posted August 5, 2006 Author Share Posted August 5, 2006 thanks :) Link to comment https://forums.phpfreaks.com/topic/16670-order-by-date-display-newest-item/#findComment-69994 Share on other sites More sharing options...
onlyican Posted August 5, 2006 Share Posted August 5, 2006 Mysql actually stores dates in the format of Y-m-d H:i:sWhich in translation2006-08-06 01:45:12 Link to comment https://forums.phpfreaks.com/topic/16670-order-by-date-display-newest-item/#findComment-70001 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.