[SOLVED] Editing Date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
luketheduck
Forum Newbie
Posts: 18
Joined: Mon Apr 19, 2004 9:13 am
Location: Aylesbury, Bucks, UK

Editing Date

Post 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!
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post 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.
User avatar
luketheduck
Forum Newbie
Posts: 18
Joined: Mon Apr 19, 2004 9:13 am
Location: Aylesbury, Bucks, UK

Post by luketheduck »

Thanks a lot.
Post Reply