I want to find weeks from a specific date
If date =26-07-2017
I want week numbers corresponds to the date
Start date = date and end date should be week date
If i understand your question, you want number of the week in year.
to do that you need to do something like this:
int weekNumber =
actualWeek.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
with that number you can get dates limits of that week:
LocalDate week = actualWeek.with(ChronoField.ALIGNED_WEEK_OF_YEAR, weekNumber);
this.startDate = week.with(DayOfWeek.MONDAY);
this.endDate = startDate.plusDays(6);
where startDate and endDate is a predefined kind of LocalDate variables
Related
I can easily get the start date and end of week like below.
SELECT
COUNT(*) AS reports_in_week,
DATE_ADD(mydate, INTERVAL(1-DAYOFWEEK(mydate)) DAY),
DATE_ADD(mydate, INTERVAL(7-DAYOFWEEK(mydate)) DAY)
FROM mytable
where WEEK(mydate,1) = '29'
GROUP BY WEEK(mydate,1)
but the problem is that case indexing of column date is not working, if i pass date range between indexing will work, i try to get the start date and end date of week using week number;
I am starter in mysql please help.
If you want to filter on a given week and year, then one option is to use str_to_date() to generate a date range from a year and week number:
where
mydate >= str_to_date('2020-29 Monday', '%Y-%u %W')
and mydate < str_to_date('2020-29 Monday', '%Y-%u %W') + interval 7 day
The %u specifier represents a week number, with Monday being the first day of the week (so this is like WEEK() in mode 1, which your query uses).
The above where predicate would take advantage of an index on mydate - which seems to be your purpose here.
I want to calculate start date and end date for the particular given week in the month , (assuming my week starts on monday and ends on sunday).
So, What I want is if I select any week number lets say 1,2 ,3 or 4 I should be able to calculate the start date for that particular week and end date .
In addition to the week number for that particular month , I will also give an input of year and month.
selection of year month and week number will be from HTML page through a drop down select option.
And I am looking for some efficient way of doing this .
Use Moment.js
Get the value of week number
var weeknumber = moment("07-27-2017", "MM-DD-YYYY").week(); console.log(weeknumber);
I am trying to select the current date based on the weeknumber in the weekstu table.
so lets says we are in week 1 which started Monday the 25/11/2013. I am trying to get that date based on using today date which is the 28/11/2013. Week 2 will be the Monday the 2/12/2013. The query I have below doesn't return any record. Is this possible to get the beginning of the week based on today date?
table:weekstu
weekid
startdate
setid
weeknumber
startdate
Table:week
weekid
setid
SELECT * from weekstu ws
JOIN week w ON ws.setid = w.setid AND ws.weekid ON w.weekid
WHERE ws.weeknumber = `1` AND startdate = CURRENT_TIMESTAMP
You can determine the beginning of the week like:
select adddate(curdate(), interval 1 - dayofweek(curdate()) day)
Note that a condition like:
startdate = CURRENT_TIMESTAMP
Will only match rows that have the exact current timestamp up to the millisecond. Unlike curdate(), current_timestamp contains time information as well as date information.
DATE_FORMAT(date,format)
%b Abbreviated month name (Jan..Dec)
%W Weekday name (Sunday..Saturday)
DATE_FORMAT(NOW(),'%W')
REF: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
I am trying to select records from a database only if they match today's date. The format for the date in the database is 2012-06-20 9:30:00 I am using the statement SELECT id FROMnewsreportsWHERE DATE(newsdate) = CURDATE() but it doesn't not return any records for today?
Screenshot of column with dates
http://img135.imageshack.us/img135/8399/2347f03df0394cd898c7fc5.png
DATE_FORMAT(NOW(),'%Y-%m-%d') = FORMAT_DATE(NOW(newsdate), '%Y-%m-%d')
Or better:
DATE(newsdate) = DATE(NOW())
The best way is to store the additional column with 2001-09-11 date format and compare this one
Example, thanks to #Conrad Frix
It looks like the curdate function is going to give you something different than the date format you've got in the database.
Take a look at the docs here
MySQL Date and Time Functions
It's supposed to return a date in this format:
2008-11-11
So, you could either search for a date range between curdate() and curdate() + INTERVAL 1 DAY (untested), or store the dates in the curdate() format.
I have a mysql table named payment and there is a field in it called next_due_date which holds a manually entered date value from the user in yyyy-mm-dd format and the type is VARCHAR. I tried
select * from payment where next_due_date >= '$strtdate' AND next_due_date <= '$endDate';
$strtdate holds current date and $endDate holds the date value before 30 days from the current date.
Logic issues - you are asking for records where the next_due_date is AFTER today AND where the next_due_date is BEFORE 30 days ago. Think about that and you'll see why you get no records :)
You probably want something more like:
select * from payment where next_due_date <= '$strtdate' AND next_due_date >= '$endDate';
Although that still looks 'weird' - probably because instead of:
"$strtdate holds current date and $endDate holds the date value before 30 days from the current date."
Perhaps you want:
$strtdate holds 30 days before now and $endDate holds the current date.
THEN you can have:
from payment where next_due_date >= '$strtdate' AND next_due_date <= '$endDate';
If you ensure that strtdate and enddate are in a yyyy-mm-dd format then the following should work:
select * from payment where next_due_date <= '$strtdate' AND next_due_date <= '$endDate';
I assume you want to select records where the due date is within the start and end date range?