www.webdeveloper.com
Results 1 to 4 of 4

Thread: [MySQL] datetime ---> number

  1. #1
    Join Date
    Oct 2005
    Location
    Hong Kong, China
    Posts
    39

    [MySQL] datetime ---> number

    Hi!
    I've a table with a coloum "dob", the type of it is datetime.

    I could like to convert the datetime to number. For example, 1980-12-28 00:00, I want it convert to 19801228.

    How can I do it in MySQL (through phpMyAdmin)?

    [see also this thread]

    Thanks in advance!!

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    Code:
    SELECT DATE_FORMAT(`dob`, '%Y%m%d') AS `date_ymd` FROM `table_name`;
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Oct 2005
    Location
    Hong Kong, China
    Posts
    39
    Quote Originally Posted by NogDog
    Code:
    SELECT DATE_FORMAT(`dob`, '%Y%m%d') AS `date_ymd` FROM `table_name`;
    Thanks for your reply!

    What else if I want to MD5 it?

    I can do the following.
    Code:
    SELECT MD5(dob) FROM table_name
    But, how can I do MD5 with your query?
    I've tested the below, but it not work.
    Code:
    SELECT MD5(DATE_FORMAT(`dob`, '%Y%m%d') AS `date_ymd`) FROM table_name
    Thanks again!

  4. #4
    Join Date
    Oct 2005
    Location
    Hong Kong, China
    Posts
    39
    I've got the answer.

    Code:
    SELECT MD5(DATE_FORMAT(`dob`, '%Y%m%d')) FROM table_name

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles