show only weekday from date - asp.net

I'm trying to use a date value I have in my table to show the start date of a holiday as the day value (Monday, Tuesday etc) how would be the best way to go about getting the start day value in this format in VB.NET?
I'm currently working with the date format dd/mm/yy.

Use Weekday and WeekdayName functions
WeekdayName(Weekday(startDate))
Weekday , which returns a number that indicates the day of the week of a particular date. It considers the ordinal value of the first day of the week to be one.
WeekdayName , which returns the name of the week in the current culture that corresponds to a particular weekday number.

Related

Year-month-week expression

I have a data written in specific expression. To simplify the data, here is the example I made:
df<-data.frame(date=c(2012034,2012044,2012051,2012063,2012074),
math=c(100,100,23,46,78))
2012034 means 4th week of march,2012. Likewise 2012044 means 4th week of April,2012. I was trying to make the values of date expressing some order. The reason why I have to do this is because when I don't change them to time expressions, x axis of the scatter plot looks really weird.
My goal is this:
Find the oldest date in date column and name it as 1. In this case, 2012034 should be 1. Next, find the second oldest date in date column and calculate how many weeks passed after that date. The second oldest date in date is 2012044.So, 5 weeks after the oldest date 2012034. So it should be changed as 1+5=6. So, likewise, I want to number the date to indicate how many weeks have passed since the oldest date
One way to do it is by also specifying the day of the week and subtract it at the end, i.e.
as.Date(paste0(df$date, '-1'), '%Y%m%U-%u') - 1
#[1] "2012-03-22" "2012-04-22" "2012-05-01" "2012-06-15" "2012-07-22"

How to find a previous weekday (Sunday, Monday, etc.) from a specific date using Momentjs

I'm trying to figure out how to build code that will find the 'MM/DD/YYYY' date of a previous day of the week in relation to a given date, which is 04/10/18.
If I've understood Momentjs' documentation correctly, I think I can use negative weekday numbers to find a past 'X-day' from a specific date.
I know the date I'm using is a Tuesday, so I thought if I gave the weekday function the numerical representation of last Tuesday (-2), I would get the past Tuesday, '04/03/2018'. The problem is that when I run the following check:
expect(await moment('04/10/2018', ['MM/DD/YYYY']).weekday(-2).format('MM/DD/YYYY')).toBe('04/03/2018');
I get a result of '04/06/2018' instead.
The returned value is correct. The function .weekdays(-2) computes two weekdays earlier than the given moment.
In your example, two weekdays before a Tuesday would be a Friday, because one weekday before Tuesday is Monday, and one weekday before that is Friday, so Tuesday 4/10/2018 - 2 weekdays = Friday 4/06/2018.

Calendar not displaying all stored dates

I am using an ASP calendar to show a list of dates, however the way the calendar overlaps and may show the last few dates of March, with the entire month of April, with the first few days of may(please see images below) is causing a problem.
I have set the 'startDate' and 'endDate' to be the start and end of that month. So if the user clicks 10th April, it will show all the stored dates btn 1st april to the 30th april. I need to change this to include the month b4 and the month after, SO any date in april will include all of March, April and May.
'Green is the date selected by the user, red is todays date, and blue are the stored dates in the DB table.'
DateTime startOfMonth = new DateTime(DiaryDate.Year, DiaryDate.Month, 1);
DateTime endOfMonth = startOfMonth.AddMonths(1).AddDays(-1);
The above code selects the first and last date of each month (of the chosen date)
I want to select the entire previous current and next month
not sure on the correct syntax. any help appreciated?
Try this:
// First, get the dates a month before - and after - the specified date.
DateTime nextMonth = DiaryDate.AddMonths(1);
DateTime lastMonth = DiaryDate.AddMonths(-1);
// Get the last day of next month.
DateTime endOfNextMonth = new DateTime(nextMonth.Year, nextMonth.Month,
DateTime.DaysInMonth(nextMonth.Year, nextMonth.Month));
// Get the first day of last month.
DateTime startOfLastMonth = new DateTime(lastMonth.Year, lastMonth.Month, 1);
Now you can simply use endOfNextMonth and startOfLastMonth as your "boundary" dates, as you are currently doing with startOfMonth and endOfMonth.

Why is last day of this year week 1 in oracle?

Why is this showing week 1? Although it's last day of year 2012.
to_char( to_date('31-DEC-12'), 'IW' )
Because, according to the ISO standard, we are in week 1.
http://www.epochconverter.com/date-and-time/weeknumbers-by-year.php?year=2013
The date format IW in Oracle returns the
Week of year (1-52 or 1-53) based on the ISO standard.
http://www.techonthenet.com/oracle/functions/to_date.php
For a non-ISO based year, you can try using the format WW.

SQLite : obtain current week

I'm trying to obtain the current week for date comparison in SQLite.
I have no problem for last month, last year, today, yesterday... but don't find the solution to have the current week.
I tried lot of things like:
SELECT tastings.* FROM tastings
WHERE (DATE(tastings.date) > DATE('now','weekday 1','+ 7 days'))
Can you help me ? Thanks.
This code gives you the week number where the first day of week is monday. It also works well for last and first weeks of the year.
strftime('%W', 'now', 'localtime', 'weekday 0', '-6 days')
I guess you want compare 2 date, Assume you have a table named _testTbl and have 3 column _id INTEGER, _name TEXT, _recordDate TEXT
you want name that record this week
you can use below code:
SELECT * FROM _testTbl
WHERE _recordDate > datetime('now', 'start of day', 'weekday 6', '-7 day')
note that this week start by saturday (sunday 0, monday 1, ..., saturday 7)
this t-sql means:
datetime is a sqlite date and time function.
first parameter is given time: 'now' means the current time.
second parameter take the time to start of day.
third parameter take time to the next weekday number (in this case, saturday).
fourth parameter take time to start of week
What is stored inside the tastings.date column? Note that SQLite does not have “timestamp” type affinity, so probably you store Text (some representation of the date) or integer (julian day, epoch…)
All time and date functions expect a valid time string and convert that time string to another string format. If tastings.date contains a week number then use:
AND cast(tastings.date AS TEXT) = strftime('%W','now')
This helps me to compare the 2 dates using the week of the year.
AND ( strftime('%W', tastings.date) = strftime('%W', 'now') )
Thanks you.

Resources