Jump to content

[SOLVED] how to insert date read from url-variable into database DATE field...


mac007

Recommended Posts

Hi, all:

 

I have this problem, where I want to be able to insert a date that's coming from url-variable, like this...

 

www.site.com/page.php?name=john&date=06152009

 

Also, as you see, the date-variable format comes as month, day, year. So how can I insert this date into my mysql db table? I can usually insert current times into my table with functions like NOW(), and other similar stuff, but how do I grab this variable and make it possible to insert back into my DATE field in my table??

 

thanks!!  appreciate any help...

Hi, PFM... thanks for the tip!  it worked beautifully!

This is the code I used if it helps anybody...

 


<?php 
  $newdate = $_GET['startdate'];
  $newdateMonth = substr($newdate,0,2);
  $newdateDay = substr($newdate,2,2);
  $newdateYear = substr($newdate,4,4);
  $newFinalDate = $newdateYear . "-" . $newdateMonth . "-" . $newdateDay;
  echo  $newFinalDate;
  ?>

 

the final echo line is what I used to populate my hidden "date" form field... which inserts the date into my table's DATE field. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.