Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    445
    Thanks
    7
    Thanked 3 Times in 3 Posts

    convert 2012-01-08 16:13:54 to time()

    How do I convert the following format to unix time ?

    2012-01-08 16:13:54

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,341
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    First you need to explode the string by the space.

    Then you need to explode the date by the /'s
    Then you need to explode the time by the :'s

    Then you need to re-arrange all those 6 variables and run them through mktime()

    You may also be able to feed it into strtotime() however that isn't as reliable (it won't take some timestrings according to the PHP versions and unlike most things, the php manual doesn't state which versions support what timestrings - EG "first day of <month>" doesn't appear to work below versions 5.3.0)
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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