Activity Stream
48,167 MEMBERS
6826 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1.     
    #1
    Member

    Default mysql php - select * where date = today?

    Hello, I am trying to do a mysql query to get all the rows where date = "today".....

    The problem is, I store my downloads date using:
    $date = time();

    is a mysql text field, which I'm guessing is really bad / slow?

    Can anyone provide me with a better way to store dates and then also provide me with a mysql_query to select all that have been added today.


    Thank you.
    c0rrup Reviewed by c0rrup on . mysql php - select * where date = today? Hello, I am trying to do a mysql query to get all the rows where date = "today"..... The problem is, I store my downloads date using: $date = time(); is a mysql text field, which I'm guessing is really bad / slow? Can anyone provide me with a better way to store dates and then also provide me with a mysql_query to select all that have been added today. Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Respected Member
    Date should be a numeric 11 byte int field for the date storing. Be sure to use a key index of the date.
    for Today only
    select * from table WHERE substring(from_unixtime(my_date),1,10) = CURDATE()

  4.     
    #3
    Member
    Yes, all timestamps should be set as int.

    I would avoid using any extra MySQL processing, though, especially since you're generating your original timestamp with PHP's time().

    Something like this would suffice:

    Code: 
    $today = strtotime('12:00:00');
    
    $sqlQuery = "SELECT * FROM theTable WHERE the_time >= {$today}";
    Coder for hire. I'm an experienced web developer with vast knowledge of PHP, HTML, CSS, MySQL, JavaScript, SEO, and web servers. I also write code for Windows programs with Visual Basic and C#.NET.

    All products are written quickly with efficiency, and security in mind.

  5.     
    #4
    Respected Member
    A little Mickey Mouse.. And won't work..... Adding extra undeeded code is really bad programming.

  6.     
    #5
    Member
    If you create a time stamp within PHP, you should compare it with PHP. Mostly because within the PHP system, an offset may be used within the time function or the date_default_timezone_set. Inconsistent code is really bad programming.
    Coder for hire. I'm an experienced web developer with vast knowledge of PHP, HTML, CSS, MySQL, JavaScript, SEO, and web servers. I also write code for Windows programs with Visual Basic and C#.NET.

    All products are written quickly with efficiency, and security in mind.

  7.     
    #6
    Respected Member
    You are kidding. Right? Where did you get your Mysql training?

    So you want to create a variable in php and read the the mysql data and move the date field to a php on each record then compare?

    Well that is exactly what you just said. You just don't quit do you.. Nothing in your head but book learning. No real experience in database design and implementation.

    It is your opinion but keep it to yourself.

  8.     
    #7
    Member
    You're brilliant.

    You'd rather two functions be executed over every row to make a comparison. Instead of one simple comparison, you'd rather over complicate it in an irrational way.

    I lack experience? Yeah... that's why you're telling someone to use an expensive string function and an unnecessary timestamp conversion on EVERY ROW.
    Coder for hire. I'm an experienced web developer with vast knowledge of PHP, HTML, CSS, MySQL, JavaScript, SEO, and web servers. I also write code for Windows programs with Visual Basic and C#.NET.

    All products are written quickly with efficiency, and security in mind.

  9.     
    #8
    Member
    Website's:
    CodeSociety.net
    if u dont understand time() or mktime(), just store ur dates using date field. google mysql date

    if ur storing using time(), change ur field type to INT, since its faster then using VARCHAR or CHAR or similar.



  10.     
    #9
    Respected Member
    Quote Originally Posted by Buddah View Post
    You're brilliant.
    Thank You.


    You should really spend some time running benchmarks and testing before yipping and yapping..

  11.     
    #10
    Member
    You're 100% right. It's perfectly logical that a query with two functions is faster than one with 0 functions.

    Again, sheer brilliance.
    Coder for hire. I'm an experienced web developer with vast knowledge of PHP, HTML, CSS, MySQL, JavaScript, SEO, and web servers. I also write code for Windows programs with Visual Basic and C#.NET.

    All products are written quickly with efficiency, and security in mind.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Help me select Hosting and DNS Company ..
    By powermatrix in forum Webmasters, Money Making
    Replies: 6
    Last Post: 9th Jan 2012, 09:33 AM
  2. [help] Select Distinct - sql
    By Solutho in forum Web Development Area
    Replies: 2
    Last Post: 27th Apr 2011, 09:49 AM
  3. Help Me Select My Phone
    By Glenn in forum General Discussion
    Replies: 26
    Last Post: 29th Nov 2010, 05:05 PM
  4. Plz select The better theme
    By Raj24 in forum Forum and DDL Discussion
    Replies: 14
    Last Post: 11th Jun 2010, 09:43 AM
  5. Select all IPB 3.0
    By bmoeller in forum Webmaster Resources
    Replies: 3
    Last Post: 15th Feb 2010, 12:19 AM

Tags for this Thread

BE SOCIAL