runnerjp Posted February 5, 2008 Share Posted February 5, 2008 how would i record some ones bob into a table like so day/month/year ?? at the moment i set it in the my table as date and 0000-00-00 the insert function is just <input id="dob" name="dob" type="text" size="25" value="" maxlength="255"></td> Quote Link to comment https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/ Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 You don't want to record it like that, leave it as 0000-00-00 and then format it for display as you see fit. Quote Link to comment https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-458911 Share on other sites More sharing options...
chronister Posted February 5, 2008 Share Posted February 5, 2008 <?php $query = "SELECT db_timestamp FROM table WHERE this == that"; $result = mysql_query($query); while($row = mysql_fetch_object($result)) { $db_timestamp = $row->db_timestamp; } echo date('m/d/Y', strtotime($db_timestamp)); ?> Something like that should work. Quote Link to comment https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-458912 Share on other sites More sharing options...
runnerjp Posted February 6, 2008 Author Share Posted February 6, 2008 mmm still stuck...i dont understand how i would get users to enter the dob info and then pull it out? Quote Link to comment https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-459568 Share on other sites More sharing options...
revraz Posted February 6, 2008 Share Posted February 6, 2008 You need to force them to use a certain format to enter the date. If its not YYYY-MM-DD then after they enter in whatever format you want, convert it to the correct format to store it. Quote Link to comment https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-459771 Share on other sites More sharing options...
haku Posted February 6, 2008 Share Posted February 6, 2008 Why not use drop-down menus? That way the format is guaranteed to be how you want it. Personally, I think all dates/times should be stored in databases as unix timestamps. Anything can be easily converted to a unix timestamp using mktime(), and unix timestamps can be easily converted to anything using date(). And unix timestamps are the easiest to do math functions with. Quote Link to comment https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-459782 Share on other sites More sharing options...
revraz Posted February 6, 2008 Share Posted February 6, 2008 Myself personally, I hate drop downs for time and dates. Quote Link to comment https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-459786 Share on other sites More sharing options...
haku Posted February 6, 2008 Share Posted February 6, 2008 I can understand that. But for an inexperienced programmer who doesn't know how to ensure that dates are formatted correctly, its a fairly easy method to implement to ensure the format is correct. I personally built a customized php-based calendar that I use as an ajax pop-up that works good for me. Quote Link to comment https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-459789 Share on other sites More sharing options...
Bauer418 Posted February 6, 2008 Share Posted February 6, 2008 I would say, allowthe users to post the DOB as mm/dd/yyyy, then use PHP's calendar/date functions to: - Verify the date - Convert it to a UNIX timestamp - From the timestamp, convert it to YYYY-MM-DD - Insert it into the DB At this point, whenever you need the date, you can use MySQL to format it and return it for you. In my opinion, MySQL date functionality is much better than PHP's, so using MySQL formatted dates in the tables almost always seems more logical than using UNIX timestamps Quote Link to comment https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-459791 Share on other sites More sharing options...
revraz Posted February 6, 2008 Share Posted February 6, 2008 No real reason to convert it to unix time if you are then going to convert it to mysql time. Quote Link to comment https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-459797 Share on other sites More sharing options...
runnerjp Posted February 6, 2008 Author Share Posted February 6, 2008 way brought up big bebate lol.... any 1 point me to sum scripts to play with for myself? Quote Link to comment https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-460014 Share on other sites More sharing options...
runnerjp Posted February 7, 2008 Author Share Posted February 7, 2008 bmp Quote Link to comment https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-460659 Share on other sites More sharing options...
aschk Posted February 7, 2008 Share Posted February 7, 2008 !Stop bumping your posts! Google it! Do some leg work... You've been given plenty of suggestions just work out your method. Dropdowns are a good option, but as one poster suggested they DON'T guarantee a format (XSS will circumvent this). Basically decide what you want to "encourage" the user to enter. If they don't enter your format its an error (tell them so) and if they do enter the format (e.g. dd/mm/yyyy) then use PHP to turn it into a database friendly format (i.e. yyyy-mm-dd). Bauer418 basically told you this already. Quote Link to comment https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-460664 Share on other sites More sharing options...
nezbo Posted February 7, 2008 Share Posted February 7, 2008 i would use mktime(); i am not to sure of the exact script but i would look at. $newTime = mktime(0, 0, 0, 1, 1, 1998);//DOB then i would save the $newTime to the database as an int(12) then when you want to diaply it use $dob = date("d-m-y" $newTime) this way you can display the time and date what ever way you want Neil Quote Link to comment https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-460816 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.