Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date Issue: 30/11/-0001

Tags:

javascript

php

I have a java script calendar control on my webpage for managing dates, in some time the date value is stored in my DB as "30/11/-0001".

It will be more appreciated if any one help me, please.....

like image 237
Prabhu M Avatar asked Jun 24 '11 15:06

Prabhu M


4 Answers

The date you are trying to set is probably empty. I have the same issue with a Symfony2 project where DateTime's stored in SQL with a value of '0000-00-00 00:00:00' result in "30-11--0001" when parsed by Twig's date filter.

like image 93
Rudy Broersma Avatar answered Nov 06 '22 07:11

Rudy Broersma


After 2 days i got the solution using notes on php.net:

Note: If the number of the year is specified in a two digit format, the values between 00-69 are mapped to 2000-2069 and 70-99 to 1970-1999. See the notes below for possible differences on 32bit systems (possible dates might end on 2038-01-19 03:14:07).


Note: The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Prior to PHP 5.1.0, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. For 64-bit versions of PHP, the valid range of a timestamp is effectively infinite, as 64 bits can represent approximately 293 billion years in either direction.

because of this problem they are showing 01-01-1970 or 30-11--0001

So you may have to put Validation from where you taking inputs.

From My Side: I am taking Android side value so i have created Regular Expression for that.

You can test Regex here.

Hope it will helps you.

like image 42
Pratik Butani Avatar answered Nov 06 '22 09:11

Pratik Butani


You need to do some testing on your front end and get the SQL statements that are constructed with different inputs and look at what's being inserted into the database. A malformed date in the SQL query may be the culprit for the db value you're seeing.

like image 1
FinalForm Avatar answered Nov 06 '22 07:11

FinalForm


if (!empty($this->dob && $this->dob != '0000-00-00')) 
{
        $dob = date_format(date_create($this->dob), "d-m-Y");
} else {
        $dob = '';
}

Add this condition to resolve this date issue $this->dob != '0000-00-00'

like image 1
Sundar Avatar answered Nov 06 '22 08:11

Sundar