Jump to content

Recommended Posts

Here's an easy question (I think).

 

Is it possible, when doing a MySql Query to include a date() string?

 

For instance, if I'm doing:

 

SELECT * FROM table WHERE field LIKE 

 

Would it be possible to enter in something like "date(Y) after "LIKE?"  If so, what is the syntax?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/132139-solved-easy-question-mysql-query/
Share on other sites

If you need to get really specific about dates you can use this approach:

<?php
$sql = "
SELECT
    COUNT(id) as total
FROM
    table
WHERE 
    date >= FROM_UNIXTIME(".mktime(0, 0, 0, date("m"), date("d"), date("Y")).")
";
?>

 

There might be a better way, but I've used this to find things like, "How many people registered this week?" or, "How many uploads have there been today?", etc...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.