top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to enter a date 01/01/1901 into mysql date field using PHP?

+2 votes

I have a date field on an html form that users may leave blank. If they do leave it blank I want to write the date 01/01/1901 into the mysql table. How can I accomplish this and where in my .php script file should I put the code?

posted Jan 10, 2014 by Sumit Pokharna

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

In your validation routine, check to see whether the date coming from the user is blank or not (if it's not blank, make sure it's valid).

If it's valid, assign it to a variable in the format 'yyyy-mm-dd'. If it's blank put '1901-01-01' in the variable.

When you do you MySQL statement use that variable. You should be storing dates in the database as yyyy-mm-dd format, not mm/dd/yyyy.

answer Jan 10, 2014 by Majula Joshi
Similar Questions
+3 votes

I am trying to calculate a date sequence using $i in conjunction with " (so the represented # is "seen" by PHP)

The code results in 2 errors:

Notice: Undefined variable: i_days_ago in test.php on line 9
Notice: Undefined variable: i_days_ago in test.php on line 13

Is there a way to do this without creating these errors and also "NOTICE" errors? The dates being calculated will be used in a database query (used to generate a report based on the activity between the starting and ending dates).

+2 votes

I always hate dealing with date/time stuff in php - never get it even close until an hour or two goes by....

anyway I have this:

// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);

Currently the results are:

exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.

BUT time_left is 07:43:04 when it should be only "00:43:04". So - where is the hour value of '07' coming from?? And how do I get this right?

0 votes

I have php script form which I used to input Members Details of my system into the MySQL database. My requirement is to display the last member's details in a input box.