Page 1 of 1

Editing Date

Posted: Mon Jul 05, 2004 5:59 am
by luketheduck
I have a date field in a database storing details (lets say it's a date of birth). I can input the date when adding to the database - I'm using dropdown menus for Day, Month and Year. The script creates a timestamp and stores to the database, no problems.

What I can't do though, is edit the date. How do I convert a timestamp so that it shows in 3 parts on the same dropdown menus?

Hopefully this makes sense!

Posted: Mon Jul 05, 2004 7:12 am
by launchcode
Rip it apart bit by bit - the least overhead method would be something like:

Code: Select all

<?php
	$ts = '2004-08-12 13:45:03';
	$year = substr($ts, 0, 4);
	$month = substr($ts, 5, 2);
	$day = substr($ts, 8, 2);
	$hour = substr($ts, 11, 2);
	$min = substr($ts, 14, 2);
	$sec = substr($ts, 17, 2);
	
	echo "$year $month $day $hour $min $sec";
?>
You could also split the time stamp on the hypen and colons, but there's no need to go creating all those arrays really. The above will work for any MySQL time stamp.

Posted: Mon Jul 05, 2004 7:33 am
by luketheduck
Thanks a lot.