SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    human date to timestamp

    Hi,

    I-ve got this date:

    19.11.2008 09:00:16

    Is it possible to turn it into a timestapm that I could store in a db?

    Thanks in advance

    Regards,

    -jj.

  2. #2
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    http://uk3.php.net/manual/en/function.strtotime.php

    or, you could use a regular expression. I don't entirely trust functions that say 'give me something and ill try and output something useful!' - I like it's behaviour to be well defined, so I know what I can expect given different inputs!

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,247
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by jjshell View Post
    19.11.2008 09:00:16
    you could also pass that string directly into mysql and use its STR_TO_DATE function to make a valid DATETIME value, or use STR_TO_DATE nested inside the UNIX_TIMESTAMP function to turn it into a unix epoch integer

    you did not really say whether you wanted to store a datetime value or a "timestamp" value (which many people interpret as being the unix epoch timestamp)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $date '19.11.2008 09:00:16';
    list(
    $date$time) = split(' '$date);
    list(
    $d$m$y) = split('\.'$date);
    $timestamp strtotime("$y-$m-$d $time");
    echo 
    date('Y-m-d H:i:s'$timestamp); 
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


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
  •