user895314
user895314

Reputation: 77

Strange Date Issue

I have a form where users can enter a birthdate. If a date prior to 1970 is entered, e.g. 1964, it is saved in the database as 2064. Can anyone shed some light on what is happening? Thanks. I am formatting the dates for MySQL using the function below:

function formatdate( $s ) {
    $date = date_create($s);
    return date_format($date, 'y-m-d');
}

Upvotes: 0

Views: 53

Answers (2)

Joe Stefanelli
Joe Stefanelli

Reputation: 135938

Use a capital Y in your format mask to return a 4 digit year.

Upvotes: 1

Sean Bright
Sean Bright

Reputation: 120714

MySQL assumes that years less than 70 (when not given as a 4 digit year) are in the 21st century and not the 20th. You should format as a 4 digit year to avoid this problem:

return date_format($date, 'Y-m-d');

Upvotes: 1

Related Questions