2

I have a day, month and year in php variables. How can I use them in a SQL INSERT statement, knowing that the field I want to insert that date is of the date type.

Thanks.

1

2 Answers 2

1

Just format the date as a string and pass it to the SQL query

   $date =  sprintf("%04d-%02d-%02d",$year,$month,$day)

where you can replace the $year, $month and $day variables with your desired input.

Sign up to request clarification or add additional context in comments.

Comments

0

Try PHP's date() method and then possibly combine with strtotime() to convert to right format.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.