Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change date 1

Status
Not open for further replies.

manicleek

Technical User
Jun 16, 2004
143
GB
can anyone tell me how I can take a date entered into a form as dd/mm/yyyy (in 1 text field with the slashes) and change it into yyyymmdd for mysql and also how to change back again

thanks
 
OK I've got something putting a timestamp in my db but now on output I get

Code:
Warning: date(): Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in C:\sites\blog\test.php on line 24

even though the year I put in was 1985!
 
Can we see your code? Usually that occurs if you have an error in the date() function call.

Ken
 
sure

Code:
<?= date("d/m/Y",strtotime($rs["date"])) ?>

I even tried entering todays timestamp in the db and got the same error
 
How is the "date" field defined in your database? What displays if you echo $rs['date']? Where is $rs['date'] coming from?

Ken
 
currently theres a date field, its set as a varchar and contains the date stamp '484095600' which should be '02/05/1985'

the date is entered into the db using the code

Code:
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];

$date = strtotime($year."-".$month."-".$day);

then an insert sql statement
 
Ok, you're storing the UNIX date in your database as a string. Since the strtotime() function converts "pseudo english strings" to UNIX dates, you don't need to use it in the echo statement:
Code:
<?= date("d/m/Y",$rs["date"]) ?>
should produce what you're looking for.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top