SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $minute_in = date("i") is getting rounded to one digit in mySQL

    Hey there, I usually pull the hour and minute using the php date() and place it in their own column for easy organization sake.

    So the minute is getting pulled as $minute_in = 06 but when it is place in the db it is 6

    my current solution is lame...please help

    Code:
    if (strlen($minute) == 1) { $minute = "0".$minute; }
    Jman

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're saving it as an integer, and integers don't have leading zeros. Use a VARCHAR column. Better yet, use a DATETIME column - I can't envision a single situation where having separate hours and minutes would be useful.
    PHP questions? RTFM
    MySQL questions? RTFM

  3. #3
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats for the the VARCHAR hint, it worked, I tried decimal (2,0) but that didn't work.

    To answer your questions - I use it to order lots of info by time I like manipulating/creating mysql queries and letting the db does the sifting.

    An example would be I want to see whats happening from 4 to 5 o'clock Monday through Friday (analysis database traffic).

    I'm definitely open to learning new ways - Jman

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You should really use a DATETIME column. It'll make all your date manipulation easier. Just take a look at all the functions available for manipulating dates and times:

    http://dev.mysql.com/doc/refman/5.0/...functions.html

    Code:
    SELECT *
    FROM table
    WHERE HOUR(your_datetime) >= 4
      AND HOUR(your_datetime) <= 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
  •