0

I searched the site already to see if this question has been addressed already and found no results, but if it has then I appologize and if you can link me to that thread I'll refer to that to solve my problem.

I am trying to save a date in MySQL using PHP and it doesn't seem to be working. The field in MySQL is the "date" type and when I read data from that field it shows as 0000-00-00, so I have tried saving the data as 2009-09-24 for example, but it doesn't seem to work. I have tried saving it with quotations to make it a string, and without quotations and I still can't seem to figure it out.

Does anyone know how I can format the date propely so I can save it in MySQL?

Thank you very much!

1 Answer 1

1

Try using the following where $t is a timestamp (time()) or nothing

function MysqlDate($t=0)
{
    if ($t==0)
        return date("Y-m-d H:i:s");
    else
        return date("Y-m-d H:i:s", $t);
}

var_dump(MysqlDate());
Sign up to request clarification or add additional context in comments.

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.