Jump to content

Recommended Posts

Hi! :)

I'm sure this is a stupid question but I've read my eyes out and still cant figure it out!

 

I have a form where i among other data fill in a date. This is a regular textbox.

How do i get this date into my MySQL Table?

 

my date variable looks like this:

$date = "28.01.2007";

 

My collumn date is a date collumn. I also know that MySQL onlu supports date form 2007-01-28, but even when i make my variable:

$date "2007-01-28";

it wont work.

 

How do i in the correct way insert a date to my MySQL database from a single textbox in a form?

also tried to convert 3 textboxes(y-m-d) in to php date() function and then insert it into my database still no luck.

Link to comment
https://forums.phpfreaks.com/topic/88228-date-from-a-form-into-mysql/
Share on other sites

Force your users to always enter the date in the same format, then use mysql's str_to_date function...

 

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_str-to-date

 

Or, use php's date functions if you choose.  Either way, strtotime is unreliable at best with changing date formats...

 

Using your format (xx.xx.yyyy) as an example, it can only guess what "1.11.2007" is...November 1st, or January 11th?  Users may not always use the same format by default, so you have to force them to.

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.