Results 1 to 5 of 5

Thread: [RESOLVED] Converting Date Types

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Resolved [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.

  2. #2
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    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.

  4. #4
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Converting Date Types

    My Pleasure

    ILMV

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    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
  •  



Click Here to Expand Forum to Full Width