Hi There

I do have a form and a little sql query to update the row before do something else.

Problem is in the code below works when I enter the date like that= 01-02-2001 but I need to do it dynamic I know getdate() but it does not work..

include "inc/inc.php";
echo "<pre>";




if($_POST["submitButton"] == "Submit"){
        

$mn=$_POST["textMembership"];
$date = getdate();
//$today  = mktime(0, 0, 0, date("m")  , date("d"), date("Y"));

//$next2year  = mktime(0, 0, 0, date("m"),   date("d"),   date("Y")+2);

 $sql= care_query("
 

UPDATE 
Contact_positions

SET 
finished =  'getdate()',
started = 'getdate()'

WHERE 
contact_number ='$mn'

AND 
address_number= '4'");

 

 

  mssql_close($con);

Do you have any idea?

Thanks

try $date=date('m-d-Y');

Does not work :( It looks like does not recognize this value.
I have this

$day = date("d");
		$month = date("m");
		$year = date("Y");
	
		$validFrom = $day."/".$month."/".$year;											
		$validTo = $day."/".$month."/".($year+2);

and i put this values in different ways such as

SET 
finished  = '".$validTo."',
started  = '".$validFrom."'

But not working ... There should be a way to insert these variables into sql statement but I have no idea yet.

If you are using MySQL and the data type of your fields in your table are DATETIME, then what you need to know is that the dates are stored in the following format: yyyy-mm-dd, NOT in mm/dd/yyyy. So try:

$validFrom =date('Y-m-d');
$validTo=date('Y-m-d',strtotime("now +2 years"));

Thank you Hielo You are right

You could also use MySQL to figure out the date:
ie. UPDATE Contact_positions SET x=CURDATE(), y=DATE_ADD(CURDATE(),INTERVAL 1 MONTH)

I prefer using database layer for dates, just in case php and mysql times are out of sync

Thanks timhysniu, I keep that in mind!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.