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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.