Results 1 to 10 of 11
-
8th Feb 2011, 01:13 AM #1OPMember
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
-
8th Feb 2011, 03:04 AM #2Respected 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()
-
8th Feb 2011, 03:38 AM #3Member
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.
-
8th Feb 2011, 04:18 AM #4Respected Member
A little Mickey Mouse.. And won't work..... Adding extra undeeded code is really bad programming.
-
8th Feb 2011, 05:08 AM #5Member
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.
-
8th Feb 2011, 04:58 PM #6Respected 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.
-
9th Feb 2011, 12:07 AM #7Member
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.
-
9th Feb 2011, 12:15 AM #8MemberWebsite's:
CodeSociety.netif 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.
-
9th Feb 2011, 02:11 AM #9Respected Member
-
10th Feb 2011, 06:14 AM #10Member
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.
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Help me select Hosting and DNS Company ..
By powermatrix in forum Webmasters, Money MakingReplies: 6Last Post: 9th Jan 2012, 09:33 AM -
[help] Select Distinct - sql
By Solutho in forum Web Development AreaReplies: 2Last Post: 27th Apr 2011, 09:49 AM -
Help Me Select My Phone
By Glenn in forum General DiscussionReplies: 26Last Post: 29th Nov 2010, 05:05 PM -
Plz select The better theme
By Raj24 in forum Forum and DDL DiscussionReplies: 14Last Post: 11th Jun 2010, 09:43 AM -
Select all IPB 3.0
By bmoeller in forum Webmaster ResourcesReplies: 3Last Post: 15th Feb 2010, 12:19 AM
themaLeecher - leech and manage...
Version 5.03 released. Open older version (or...