Jump to content

[SOLVED] Inserting Date into mysql from form using PHP


seed

Recommended Posts

Can someone provide me some insight on how to insert a date into a mysql table. I'm trying to create an events page for a site I've created. I need to allow the user to enter a start & end date.

In mysql the fields are of type "date" - (Doesn't have to be that way if you guys suggest otherwise)

My form is requesting the date in the format of MM/DD/YYYY.

 

Can someone please provide some insight on how to get that into the mysql field.

 

 

Link to comment
Share on other sites

I figged it out. In my form the date is entered as MM/DD/YYYY so I had to create this bit of code for properly format it for mysql

 

 

$eventStartDate = $_POST['txtEventStartDate'];

 

$startYear = substr($eventStartDate, 6, 4);

$startMonth = substr($eventStartDate, 0, 2);

$startDay = substr($eventStartDate, 3, 2);

 

$startDate = $startYear . "-" . $startMonth . "-" . $startDay;

 

insert into tbl_test (col_test) values ('$startDate');

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.