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.

 

 

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');

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.