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.
Related
I have two inputs first input is for getting the date and the second input is for getting the time of the day.
For example,
User selects date: 20 January 2019 and time: 12:30 pm.
When I convert the date input to Unix timestamp I get the timestamp for 00:00 hours on 20 January 2019.
startingDate = moment(date.startsOn).unix();
So I want to add hours that I'm getting from the user into the date timestamp.
When I try to convert hours into Unix timestamp I get a timestamp for the present day along with the hours entered by the user i.e. I get timestamp for 12:00 pm on 11 January 2019.
startingTime = moment(date.startingTime).unix();
Any suggestion how I can achieve this?
I managed to do this in this way:
As I had my starting date and time in unix format
startingDate = moment(date.startsOn).unix();
startingTime = moment(date.startingTime).unix();
I had to convert them into moment format
const date = moment.unix(this.startingDate).format('YYYY-MM-DD h:mm a');
const hours = moment.unix(this.startingTime).format('HH');
Then I added hours to my date constant
var finalTime = date.add(hours, 'hours');
Then I posted this finalTime to my API.
I have to maintain an ASPX page that increments the date/time by passing a value in the querystring in this format:
636529536000000000 in reference to 31 January 2018
636530400000000000 in reference to 01 February 2018
The url format is: /reservas.aspx?t=636530400000000000
What is this date/time format?
It is the number of ticks where a tick is one hundred nanoseconds or one ten-millionth of a second. The number of ticks is measured since the epoch DateTime.MinValue (12:00:00 midnight, January 1, 0001). For example:
new DateTime(636529536000000000).ToString("F", CultureInfo.InvariantCulture)
outputs:
Wednesday, 31 January 2018 00:00:00
Could be a number of days from certain date, similar to julian date calculation:
https://en.wikipedia.org/wiki/Julian_day#Julian_date_calculation
Potentially incorporating the time as well?
Without details of the code I cant really advise from a provided value.
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.
I'm trying to get date for first day of the new year, it means that I tried something like this:
dateFrom = moment().month(0).day(01).format('YYYY-MM-DD');
But it gives me date:
2013-12-30
Instead of the
2014-01-01
How can I solve it please?
Thanks for any advice.
You are looking for date instead of day if you want to define the day of the month.
This works:
moment().month(0).date(1).format('YYYY-MM-DD');
The date method defines day of the month, docs here.
The day method defines the day of the week. From the docs:
So, by using day(1) you are asking to get the nearest Monday. In your case the nearest Monday to January 1st, 2014 is December 30th, 2013
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.