SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,079
    Mentioned
    53 Post(s)
    Tagged
    0 Thread(s)

    Convert string to date by passing pattern?

    Having trouble researching this one or coming up with my own solution. I need to be able to pass a date/time pattern that will then used to convert a string to DateTime.

    Code PHP:
    $string = '20130408164312'; // yyyymmddhhmmss
    $string2 = '2013-04-08 16:43:12'

    I should be able to pass both of those strings to a function, along with some sort of pattern string and be able to return a DateTime object. I'm trying to make this completely versatile. Ideas/functions you've already come across?

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,812
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Doesn't PHP already support this? http://us3.php.net/manual/en/datetim...fromformat.php
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  3. #3
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,079
    Mentioned
    53 Post(s)
    Tagged
    0 Thread(s)
    Ya, I was just coming back to paste that myself.. My googling skills weren't on par today I suppose. Thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •