how to get last day of a month using command prompt - cmd

I wanted to get the last day of any month which is passed using the command prompt. Can someone from you help me with the same.
There should be a command which should contain a number like 4 which stands for April and the output should contain 30.

You could use some vbscript.
if WScript.Arguments(0) = "12" Then
NextMonth=1
Else
NextMonth=WScript.Arguments(0) + 1
End If
wscript.echo(Split(DateAdd("d", -1, DateSerial(year(now), NextMonth, 1)), "/", 3, 1)(1))
Just save this into something like GetLastDay.vbs, and run it like this:
cscript /nologo GetLastDay.vbs (month number)
...where (month number) is a number from 1 to 12. Note that there is no error checking, so make sure you pass in something valid. It also assumes the current year, so if you pass in 2, you'll get 29 because this is a leap year. Next year you would get 28.
What this script does is take your month and create a date object for the first day of the month AFTER the month you supplied, and then subtract one day to land on the last day of the month BEFORE (which is the month you requested). It then uses Split() to get the day token out of the resulting date string.

Related

Show value from last day of the given month - SSRS Report Builder

In a Report Builder table I have to show the value from the last day of the given month, when the month is not expanded.
When the month is expanded, the dates have to show the specific value for that day.
Example is January with values 1 to 31 (same as the day numbers):
When January is expanded, it has to show value 1 on Jan 1.... value 15 on Jan 15... value 31 on Jan 31.
When contracted (and the table only show one row for January), it should show the last day's value of 31
Some months do not have values on all days, so the formula just need to take the last value of that given month
When I use the formula "Last()", then it works half of the time, while for some months, the value extracted is the 3rd or 4th last day of the month - do you know what is wrong here?
Hope above makes sense, and thanks for help.
I think I fixed it my self:
Using Last () formula
Learning how to make a sort order in my Union All dataset, so it came out in the right way
How to give points to my self?

Get Week Number of the year with custom day as starting day of the week

I want to use Date.WeekOfYear() Function to get Week Number for datetime values, but with a custom day as the start of the week (Let's say Saturday rather than Sunday). How is it possible in PowerQuery M?
You could use a conditional statement like this (adding 1 to the weeknumber if the day is saturday):
if Date.DayOfWeek([Date])=5 then Date.WeekOfYear([Date])+1 else Date.WeekOfYear([Date])

declared variable expression conversion

Can anyone help me convert the following lines to SSRS expressions? I'm trying to return the dates in my SSRS report so users can see the data ranges they are returning data for. My data set queries are using the these to set the date parameters. Some of the functions don't seem to work in SSRS.
EOMONTH(Dateadd(Quarter,Datediff(Quarter,0,getdate())-2,0),2) --Beg of last Quarter
EOMONTH(Dateadd(Quarter,Datediff(Quarter,0,getdate())-1,0),2) --end of last Quarter
EOMONTH(Dateadd(Year,Datediff(Year,0,getdate())-1,0),11) --beg this year
EOMONTH(Dateadd(Year,Datediff(Year,0,getdate())-2,0),11) -- beg of last year
EOMONTH(Dateadd(Year,Datediff(Year,0,getdate())-1,0),11) -- end of last year
Hope this can help you
beginning of last Quarter =FormatDateTime(dateadd("q",datediff("q","1/1/1900",today)-1,"1/1/1900"),DateFormat.ShortDate)
end of last quarter
=FormatDateTime(dateadd("s",-1,dateadd("q",datediff("q","1/1/1900",today),"1/1/1900")),DateFormat.ShortDate)
Beginning of current year
=FormatDateTime(DateSerial(YEAR(Today),1,1),DateFormat.ShortDate)
End of current year
=FormatDateTime(DateSerial(Year(Now), 12, 31),DateFormat.ShortDate)
Beginning of the last year
=FormatDateTime(DateSerial(YEAR(Today)-1,1,1),DateFormat.ShortDate)
End of the last year
=FormatDateTime(DateSerial(Year(Now)-1, 12, 31),DateFormat.ShortDate)
Note I am using FormatDateTime to get short date, you can set the format as your requeriments.

How to find the date of the first day of week given any date range of that week in vb6

How do I find the date of the first day of week given any date of current week in vb6 or classic asp?
Weekday(date)
This returns an int between 1 and 7 for sun to sat. With this it is easy to get the date of the first day, but first you need to define the first day, assuming sunday then...
DateAdd("d", -Weekday(date)+1, date)

How do I calulate week of year in Oracle using a non-standard first day of the week?

I have a query that needs to return the "week of year" of a date field but the customer of the query uses a non-standard first day of the week so TO_CHAR with 'IW' isn't returning the expected result. In this case the first day of the week is Saturday and Friday is the seventh day of the week.
With T-SQL I'd use DATEPART and SET DATEFIRST.
What is the Oracle equivalent? The Oracle answers I've found in the google all talk about setting the NLS_TERRITORY like so ALTER SESSION SET NLS_TERRITORY = 'UNITED KINGDOM'; but I'm not seeing where I can pick an arbitrary day (other than perhaps finding a territory that uses Saturday).
IW works with a Monday - Sunday week, so this should get you what you are looking for. Basically, get the week according to the day 2 days from now:
to_char(your_date + 2, 'IW')
Oracle's default week format calculates the week number from the first day of the year instead of the first day of the week.
So if a year starts on 01-jan-2009 and the first day is on Wednesday, the week No. 1 will be from 01-jan-2009 to 08-jan-2009 (wednesday to tuesday).
You can use the "iw" format (and a little tweak) if you need the week range to start from sunday through saturday. http://download-uk.oracle.com/docs/cd/B14117_01/server.101/b10749/ch9sql.htm#CIHGFJEI
Try this code below. I basically use the "IW" format and add a condition to get the week number to start from a given date.. say...01-jul-2008.
select target_date,
to_char(target_date+1,'iw') week_sun_thru_saturday,
to_number(to_char(target_date+1,'iw')) -
to_number(to_char( to_date('10-jul-2008','dd-mon-yyyy')+1,'iw')) week_from_01_jul_2008
from t;
Remember..This code will not give week number 1 from jul1st to jul-07 .unless of course 01-jul-2008 is a sunday ;)

Resources