Jump to content

date to mon - fri


Destramic

Recommended Posts

hey guys i have a little problem and not sure of the best way to tackle it, if you could help please.

i have 2 url which could be like so
 

tasks/ricky-powell/week/14/08/2018
tasls/ricky-powell/day/14/08/2018

now if /day/14/08/2018 then thats a simple query.

SELECT task FROM tasks WHERE scheduled_date = '2018-08-14'

 

but...if users selects to view tasks by week (mon-fri) then it becomes a little bit complicated.

14/08/2018 is today which is a tuesday, and i would need to get the range from date mon - fri.

would it be easier to:

 

1. ensure weekly url is a monday?

2.work out the date (mon - fri) view mysql/php

3. something else.

 

thank you.

 

 

 

Edited by Destramic
Link to comment
Share on other sites

thank you for your quick reply. i would also need friday's date.

ive been testing via sql, and think ive almost made a breakthrough, but i get an error.

SELECT 
DATE_ADD(DATE('2018-08-14'), INTERVAL - WEEKDAY(DATE('2018-08-14')) DAY) AS 'week_start',
DATE_ADD(week_start, INTERVAL 5 DAY) AS 'week_end'

 

Quote

Error Code: 1054. Unknown column 'week_start' in 'field list'

 

Link to comment
Share on other sites

Column aliases are applied on query output so week_start doesn't exist. Also the alias shouldn't be in quotes.

Continuing from my previous code
 

$monday = $dt->format('Y-m-d');
$friday = $dt->add(new DateInterval('P4D'))->format('Y-m-d');

or

SELECT ... WHERE scheduled_date BETWEEN '$monday' AND '$monday' + INTERVAL 4 DAY

 

Link to comment
Share on other sites

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.