How to get first date and last date from given month name and Year - asp.net

In my page I have on dropDown ddMonth and ddYear ...ddMonth shows jan,Feb,mar etc. ddYear as 2014,2015... . By using this How can I get the first date and last date from this 2 dropdown (ddmonth and ddYear) by using asp.net.

The first date of always starts with 1 so you can create date using day as 1
DateTime dt = new DateTime(year, month, 1);
For last date of month you can add 1 to month and subtract on day from it.
DateTime dt = (new DateTime(year, month, 1).AddMonths(1)).AddDays(-1);

Related

Fiscal Month Start Dates

I have a fiscal Month End date column. Based on this column I will have to calculate 12 month prior fiscal start date, 24 month prior fiscal start date and so on.
I cannot use add_months function here as below are the fscl month end dates. When a user chooses 01-JUL-2017, the 12 months prior date should start at 03-JUL-16.
If I use add months the date range would change to be 01-JUL-2016 to 01-JUL-2017 but I need it to be 03-JUL-2017 to 01-JUL-2017.
FISCAL MONTH END DATES
30-JAN-16
27-FEB-16
02-APR-16
30-APR-16
28-MAY-16
02-JUL-16
30-JUL-16
27-AUG-16
01-OCT-16
29-OCT-16
26-NOV-16
28-JAN-17
25-FEB-17
01-APR-17
29-APR-17
27-MAY-17
01-JUL-17
Considering that your table has all the dates in the sequence, You can use the LAG function with parameter 11 (i.e. 11th previous date in the sequence).Take the user input from the where clause as a bind Variable.
( WHERE TO_CHAR(DT,'DD-MON-YY') = :curr_fiscal_end_dt )
SELECT Prev_fisc_start_date FROM
(
SELECT DT, LAG(DT, 11 ) OVER ( ORDER BY DT ) + 1 Prev_fisc_start_dt FROM
Your_table
) WHERE TO_CHAR(DT,'DD-MON-YY') ='01-JUL-2017';

Using MomentJS to add a month returns a different day

Using MomentJS and adding a month, I wouldn't expect the day to change:
let date = moment('1995-01-25');
date.add(2, 'month');
console.log(date.day()); // Expected 25, outputs 6
You have to use date() to get date of the month, day() returns the day of the week (Sunday as 0, ..., Saturday as 6.).
See code sample:
let date = moment('1995-01-25');
date.add(2, 'month');
console.log(date.format());
console.log(date.day()); // Day of the week
console.log(date.date()); // Day of the month
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>

ASP Classic Get Next Date for a WeekDayName

I would like to specify a number that specifies the day of week and then have ASP get the upcoming date for that week day specified.
Example:
Dim xWeekDay
xWeekDay=1 ' <-- 1 would be a Monday...and Sunday would be 7
Dim NextDdate
NextDdate= ???? <-- I want to calculate and show the Upcoming Date here
So the above line would look like this when it's populated.
NextDdate=7/1/2013
Try this:
today = Weekday(Date, vbMonday)
If xWeekDay > today Then
NextDate = Date + (xWeekDay - today)
Else
NextDate = Date + (xWeekDay + 7 - today)
End If
Weekday(Date, vbMonday) is the number of the currend day of the week (with Monday being set as the first weekday). If xWeekDay is in the future (xWeekDay > today), then the next occurrence is xWeekDay - today days away. Otherwise it's xWeekDay + 7 - today days away. Add that difference to the current date and you have the date you're looking for.

Find This Weeks Monday

How do I get the date of this current week's Monday. Where Monday is the first day of the week. So if I was to look up this weeks it would return the date 1/16/2012
I am using VBScript and ASP
Many thanks in advance..
Paul
Effectively, the Weekday function returns Sunday=1, Monday=2, etc. To get the Monday of the same week, you want to subtract:
Sunday (1): 6 days
Monday (2): 0 days
Tuesday(3): 1 day
...
Saturday(7): 5 days.
Or
Days to subtract = (Weekday - 2 + 7) Mod 7
So if d is a date, the Monday of the same week can be written as:
mondayofsameweek = DateAdd("d", -((Weekday(d) + 7 - 2) Mod 7), d)
VBScript has a function called WeekDay, it return 1 - 7, not sure whether 1 is Monday though, usually you can twiddle with that.
Either way get the weekday Thursday = 4? , so then you just need to take three days off your date with thae DateAdd function
In VBScript WeekDay returns the day of the week, starting with Sunday=1 (VBScript can be quirky like that). So just subtract two (Monday=2) from that value and call DateAdd.
monday = DateAdd("d",(WeekDay(Date())-2),Date())
I know the topic is a bit old, but I figured I'd share my working solution that I think is a bit more concise.
Where dDate is your current date:
dDate = DateAdd("d", -(WeekDay(dDate, vbMonday) - 1), dDate)
The second parameters of WeekDay is the day you want the week to 'start'. For me, in the US, WeekDay corresponds the default second parameter to vbSunday. Specifying vbMonday, we just get the difference (base 1) between our current weekday and Monday.
Subtract 1 and add the inverse to your current date should obtain your result.
Example:
WeekDay(2018-03-20, vbMonday) = -((2) - 1) = DateAdd("d", -1, 2018-03-20)

Manipulating Date in Excel code

A column in an excel worksheet holds the month in this format:
Oct_2010
What I want to do is, get the last date of that month. What I figured I would do is, read the month in the cell, get the first day of the next month and then subtract one day, so I get the last date of the previous month.
But, how can I get Excel (VBA code) to read Oct_2010 as Oct 2010?
In VBA
Function LastDayFromString(sDate As String) As Date
Dim dtTemp As Date
If Not sDate Like "???[_]####" Then Err.Raise 9999, , "Invalid date string format"
dtTemp = DateValue(Replace(sDate, "_", "/"))
LastDayFromString = DateSerial(Year(dtTemp), Month(dtTemp) + 1, 0)
End Function
Used like
?lastdayfromstring("Oct_2010")
10/31/2010
How about:
=DATE(YEAR(REPLACE(A1,4,1,"/")),MONTH(REPLACE(A1,4,1,"/")),0)
Where A1=Oct_2010

Resources