Jump to content

Recommended Posts

I am inserting NOW() in a datetime field on creation of new records.

 

I want to have a "show this week's entries" link which will display records created on, or since, Monday of the current week.

 

How can I do this? E.g.

$q = "SELECT col1, col2 FROM table WHERE creation_date [blah blah]";
$r = mysqli_query($dbc, $q);

 

Thanks in advance for your help.

You can use mktime() and date() to get the last monday and then convert it into datetime format.

 

Here's a little snippet for datetime conversion, the rest is for you because I don't have much time right now.

 

function strToDateTime($input)
{
return preg_replace('/^(\d{2}).(\d{2}).(\d{4}) (\d{2})\d{2})\d{2})$/', '$3-$2-$1 $4:$5:$6', $input);
}

 

Edit: Forgot to mention, you can use > and < operators in datetime where-clauses.

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.