Computing.Net > Forums > Programming > problem with date() function in PHP

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

problem with date() function in PHP

Reply to Message Icon

Name: Deepa
Date: December 11, 2003 at 21:46:49 Pacific
OS: Windows XP
CPU/Ram: 256mb
Comment:

hi,

i'm having a table in mysql which has a column name DOB, the field of which defined as date. & i'm inserting the data into it, after converting the value receied in the form of text into date format using the following code...

$dte = date("Y-m-d", strtotime($dt));//the value in $dt is in the form "01-Dec-2003"
$db = mysql_connect("localhost");
mysql_select_db("deepa", $db);

$sql = "insert into check values('$slno','$name','$dte')"
or die("could not execute query");
$result = mysql_query($sql);

this piece of code executes fine except when the given date lies previous to year 1970.

for eg:
if the date value is given as "01-Jan-1970"..it works fine
but if the date value is given as "01-Jan-1969" or previous years...then it throws a warning as below & some junk gets inserted in to db.

Warning: unexpected error in date() in c:\apache\htdocs\mscl\check_date\submit.php on line 12

please help me out with this problem...thanx already..

regards,
deepa



Sponsored Link
Ads by Google

Response Number 1
Name: SN
Date: December 12, 2003 at 03:08:12 Pacific
Reply:

*We celebrate SN's first PHP answer*

This is a well-documented problem with strtotime() on windows:

"Note: The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, 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. "

documentation is here.

I've traditionally used select/option lists for date entering, so there is less chance of error. Then, in php, with its magical form parsing, you can just say:
$dte=$year."-".$month."-".$day
(assuming year, month and day were the input fields for the birth date column)

Good luck,
-SN


0

Response Number 2
Name: Deepa
Date: December 15, 2003 at 01:16:41 Pacific
Reply:

thanx a lot for the useful info mr.SN


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


what is pearl End Statement in VB



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: problem with date() function in PHP

date function in PHP www.computing.net/answers/programming/date-function-in-php/11309.html

Multiple Function in PHP www.computing.net/answers/programming/multiple-function-in-php/14325.html

Problems with date command in W2003 Server www.computing.net/answers/programming/problems-with-date-command-in-w2003-server/19348.html