Professional Web Applications Themes

mysql date to timestamp - PHP Development

I would like to use php to query a database and retrieve a unix timestamp. The problem is that mysql is storing the data in the date format and not a timestamp. I am sure that I can amend my query to format the date returned as a timestamp without having to do the conversion in php. Can someone tell me what to put in my db query? Thanks Ben....

  1. #1

    Default mysql date to timestamp

    I would like to use php to query a database and retrieve a unix timestamp.

    The problem is that mysql is storing the data in the date format and not
    a timestamp.

    I am sure that I can amend my query to format the date returned as a
    timestamp without having to do the conversion in php.

    Can someone tell me what to put in my db query?

    Thanks

    Ben.

    Ben Guest

  2. #2

    Default Re: mysql date to timestamp

    Ben wrote:
    >
    > I would like to use php to query a database and retrieve a unix timestamp.
    >
    > The problem is that mysql is storing the data in the date format and not
    > a timestamp.
    >
    > I am sure that I can amend my query to format the date returned as a
    > timestamp without having to do the conversion in php.
    >
    > Can someone tell me what to put in my db query?
    >
    > Thanks
    >
    > Ben.
    I think this is what you're looking for (from mysql.com):


    UNIX_TIMESTAMP(date)
    If called with no argument, returns a Unix timestamp (seconds since '1970-01-01
    00:00:00' GMT) as an unsigned integer. If UNIX_TIMESTAMP() is called with a date
    argument, it returns the value of the argument as seconds since '1970-01-01
    00:00:00' GMT. date may be a DATE string, a DATETIME string, a TIMESTAMP, or a
    number in the format YYMMDD or YYYYMMDD in local time:
    mysql> SELECT UNIX_TIMESTAMP();
    -> 882226357
    mysql> SELECT UNIX_TIMESTAMP('1997-10-04 22:23:00');
    -> 875996580
    When UNIX_TIMESTAMP is used on a TIMESTAMP column, the function returns the
    internal timestamp value directly, with no implicit ``string-to-Unix-timestamp''
    conversion. If you pass an out-of-range date to UNIX_TIMESTAMP() it returns 0,
    but please note that only basic checking is performed (year 1970-2037, month
    01-12, day 01-31). If you want to subtract UNIX_TIMESTAMP() columns, you may
    want to cast the result to signed integers. See section 6.3.5 Cast Functions.

    Regards,
    Shawn

    --
    Shawn Wilson
    [email]shawnglassgiant.com[/email]
    [url]http://www.glassgiant.com[/url]
    Shawn Wilson Guest

  3. #3

    Default Re: mysql date to timestamp

    In article <1070896005.20996.0damia.uk.clara.net>, Ben wrote:
    > I would like to use php to query a database and retrieve a unix timestamp.
    >
    > The problem is that mysql is storing the data in the date format and not
    > a timestamp.
    >
    > I am sure that I can amend my query to format the date returned as a
    > timestamp without having to do the conversion in php.
    What is the columntype for your date?

    If you have TIMESTAMP, then you could do things as
    SELECT FORMAT_DATE(date,'%d-%m-%Y %H:%i:%s') AS date

    --
    verum ipsum factum
    Tim Van Wassenhove Guest

Similar Threads

  1. Replies: 1
    Last Post: October 24th, 11:38 AM
  2. timestamp to date ?
    By Damian John Paul Brown in forum PHP Development
    Replies: 3
    Last Post: April 11th, 07:31 AM
  3. MySQL timestamp to desired date function
    By Cesar Aracena in forum PHP Development
    Replies: 2
    Last Post: September 18th, 11:39 AM
  4. [PHP] MySQL timestamp to desired date function
    By Cesar Aracena in forum PHP Development
    Replies: 0
    Last Post: September 18th, 05:12 AM
  5. Date/Time and TIMESTAMP
    By guiksye webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 2
    Last Post: July 17th, 03:51 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139