Jump to content

problen in date function


iammudassir

Recommended Posts

i have 3 column delivery_no , qty , etd (etd is date) i have a form with some rows in shape of array like this<tr>delivery_no[]qty[]etd[]</tr> <tr>delivery_no[]qty[]etd[]</tr> below is my php code if(isset($_POST['save'])) { foreach ($_POST['delivery_no'] as $row=>$del_no){ $delivery_no=$del_no; $qty =$_POST['qty'][$row]; $etd = date('Y-m-d',strtotime($_POST['etd'][$row])); // problem is here $query_array = "INSERT INTO ls_detail ( delivery_no, qty, etd)VALUES ( '$delivery_no', '$qty' , '$etd' )";echo "<br />"; if (mysql_query($query_array)){echo "ROW inserted";}}} ?> my question if i enter some date in etd[] field like 10-11-2012 i works fine and save correct value which i entered.butif i leave my etd[] blank and press save button $etd will be 31-12-1969 automatically , how i stop it , why with out any post value in etd field it save date 31-12-1969 in databaseactually my question is why my $etd = 31-12-1969 without $_POST['etd'][$row]and how i set $etd " NULL" if $_POST['etd'][$row] have no valueplease answer me with code thanks in advance

Link to comment
Share on other sites

you can set that column as " is NULL" in database to accept NULL values. as EPOCH time starts from 1st january 1970. intially it starts from that date if you dont provide any.

Link to comment
Share on other sites

I also have one problem with date. Here is my code... <?php $my_t=getdate(date("U")); print("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]"); ?> It works, output is, for example "Sunday, December 9, 2012"Now, I want to translate it to my language, which means that I don't want to display "Sunday, December 9, 2012" but "Nedjelja, 9. prosinca, 2012." It is no matter if you don't understand this, I was wondering if anyone can just write how to not display "Sunday" but, for example, "Sunnyday" Thanks :)

Link to comment
Share on other sites

You should start your own topic to solve your problems. here is the reference of date() http://php.net/dateyou can find the format available to it. It does not have any fancy naming by default but you can use conditional structure to replace the string. as if it is sunday making it sunnyday

  • Like 1
Link to comment
Share on other sites

you can set that column as " is NULL" in database to accept NULL values. as EPOCH time starts from 1st january 1970. intially it starts from that date if you dont provide any.
i already set this field NULL in my database to accept null values actually $etd = date('Y-m-d',strtotime($_POST['etd'][$row]));this line create $etd i have to stop itlike thisif $_POST['etd'][$row] is present then $etd = date('Y-m-d',strtotime($_POST['etd'][$row]));else $etd = ""how i create this line in php code ??? tell me the php code for this issue
Link to comment
Share on other sites

Set it that column Default value as NULL. so if you dont provied any date it will be set to NULL

  • Like 1
Link to comment
Share on other sites

if(isset($_POST['etd'][$row])){ your line....}else{ $etd = "";}
Set it that column Default value as NULL. so if you dont provied any date it will be set to NULL
after trying these both solution now mydatabase shows "0000-00-00" now i understand what my problem issee this$myname = "abc"$mydate = NULL or $mydate = 'NULL' (i try these both style) here $mydate is NULL but problem start when i run my sql query $query = "INSERT INTO mytable (myname , mydate ) values ('$myname' , '$mydate' )";$mydate = NULL but in query it is uner ' ' so NULL save as 'NULL' and date cannot accept it to check i run simple sql query INSERT INTO mytable (myname , mydate ) values ('abc' , 'NULL' ); i also save 0000.00.00 in datebut when i run INSERT INTO mytable (myname , mydate ) values ('abc' , NULL ); see here NULL is without ' ' now it show NULL in database so in php we are using variable to save values in database and variable are under ' ' so i am unable so save NULL in database trhough PHP , i tired i loose :(
Link to comment
Share on other sites

i think a solution when my query run it save values ('$myname' , '$mydate' ) here $mydate save as '' means (empty) and empty data save as 0000-00-00my solution is after this query i will run another query of update like thisupdate mytable set mydate = NULL where mydate = "0000-00-00" ;or give me another solution so save NULL in date field in database though PHP vairable

Link to comment
Share on other sites

see i dont understand why u want to make it as a null.. and still if u really want to make it null my advice is to not to use column date as a data type date. use column date of data type text or varchar and save $etd value in it or null.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...