Jump to content

posting dob into db


runnerjp

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-459782
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-459789
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-459791
Share on other sites

!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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-460664
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/89577-posting-dob-into-db/#findComment-460816
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.