|
-
Oct 16th, 2008, 08:00 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Converting Date Types
Is there a function in PHP that will allow me to convert from one date/time format to another?
For example:
PHP Code:
echo convdate("originalformat", "originaldatetime", "newformat");
I wish to convert dates and times from this:
16/10/2008 23:57:21
To something like this:
20081016235721
I've checked Google, but not much help from there.
Last edited by Slyke; Oct 16th, 2008 at 08:04 AM.
-
Oct 16th, 2008, 08:49 AM
#2
Re: Converting Date Types
Try this, I had written this because I couldn't find a way of converting the format of a date.
usage:
Code:
echo(format_date('16/10/2008 23:57:21'));
code:
Code:
function format_date($timestamp_date='', $result_format='YmdHis')
{
if($timestamp_date=='')
{
// Return if no variables passed
return;
}
else
{
// Split up date and time
$date_time = split(" ", $timestamp_date);
// Split up date
$date = split("/", $date_time[0]);
// Split up time
$time = split("-", $date_time[1]);
// Compile date into desired format
$result=date($result_format, mktime($time[0], $time[1], $time[2], $date[1], $date[0], $date[2]));
}
// Return resulting variable to main function
return $result;
}
Edit: I know this isn't very versatile now... I plan on making this function more efficient soon.
ILMV
Last edited by I_Love_My_Vans; Oct 16th, 2008 at 08:54 AM.
-
Oct 16th, 2008, 09:30 PM
#3
Thread Starter
Fanatic Member
Re: Converting Date Types
Hey,
Thanks for that.
I'm sure that I can work for this =). Maybe when you finish your code you could put it on the PHP site . Will marked resolved when I've got home and tested it. At work now!
Last edited by Slyke; Oct 16th, 2008 at 10:12 PM.
-
Oct 17th, 2008, 01:13 AM
#4
Re: Converting Date Types
-
Oct 17th, 2008, 02:57 AM
#5
Thread Starter
Fanatic Member
Re: Converting Date Types
Awesome dude, it worked like a charm .
Thanks for your help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|