How do I Determine The Number Of Days In A Month from a particular date in angularjs 2? - date

I am using angularjs 2 and type script.
I want the number of days in a month from a particular date given by user.
How do I Determine that?
Please help. Thanks in Advance.

As pointed out by Evgeny Shmanev, this answer is incorrect. Please see the correct answer by Zvi Tarem
You don't need angular, you can call this function:
function daysRemainingInMonth(date) {
var year = date.getYear();
var month = date.getMonth();
return new Date(year, month, 0).getDate()
}
Edit: Updated now that I know you have the date

It may be a bit late, but the right answer is a follows:
In order to find the number of days in a month, you need to get the 'date' of the 0th day of the next month:
let daysInMonth = new Date(year, month + 1, 0).getDate();

Related

How to get previous 5 days date from given date?

How to get previous 5 days date(30/11/2020) from given date?
How to get previous 5 months from given date?
Simply add a negative Duration:
DateTime nowFiveDaysAgo = DateTime.now().add(Duration(days: -5));

how to add weeks,month, year to a date in flutter

I have a date string in flutter which i am trying to add week, month and year but not sure how to do it.
in android java, we can add weeks, month, year in the following way
Calendar cal = Calendar.getInstance();
cal.setTime('2019-09-04');
cal.add(Calendar.WEEK_OF_MONTH,1); // add one week
cal.add(Calendar.WEEK_OF_MONTH, 2 ); // add two weeks
cal.add(Calendar.MONTH, 1); // add # of month
cal.add(Calendar.MONTH, 3); // add 3 months
cal.add(Calendar.YEAR, 1); // add 1 year
however, i dont know how to add this in flutter. i know i can use duration but it only accept number of days cal.add(new Duration(days: 30));
if i use duration, then i need to figure out how many number of days in a month, week, or year and it is more math. with the above code in android java, adding weeks , months or year will be taken by android. is there a way for flutter to add weeks, months or year to a date?
for example: if i have 01/31/2019 and i want to add a month then new date should be 02/28/2019. if i want add a month to 02/28/2019 then output should be 03/31/2019
same goes for weeks and years. flutter should add a week to a date if specify or a year and so on. thanks in advance
You can find everything you need on this medium article:
Top 7 Date methods
Let's suppose you have '2019-09-04', in Dart you have:
var myDate = DateTime.parse("2019-09-04 20:18:04Z");
myDate.add(Duration(days: 10, hours: 5)));
then print it out:
print(myDate.toLocal());
EDIT:
because of your comment below, to add years or month do as follow:
var date = new DateTime(2019, 9, 4);
var newDate = new DateTime(date.year + 1, date.month + 2, date.day);
You can find similar answer here: Add/Substract months/years to date in dart?

How to create a specific date in Google Script

I have a spreadsheet that asks people to enter in a day of the month when we need to send out a bill. What I want to do is create a calendar event based on that. So, essentially what I need is an event that starts at the current month, day from the spreadsheet, and continues to a specified point in time.
var monthlyDate = row[6]; // Seventh column, monthly date of payment
var curDate = new Date();
var curMonth = curDate.getMonth();
var curYear = curDate.getYear();
curDate.setDate(curMonth, monthlyDate, curYear);
Logger.log("Day of month: %s", monthlyDate);
Logger.log("Current Date: %s", curDate);
Logger.log("Current Date: %s", Date());
What I'm seeing is that the monthly date is coming in as a float "6.0" for example, and no matter what I enter in for monthlyDate in the setDate line, it keeps setting the date to 10/9/15 (Today is 10/15/15). I've hard-coded that value to many different numbers, but for some reason it's just not working.
How can I create a date (in any format) that follows the scheme "Current Month / Day from Speadsheet / Current Year" ?
The getMonth() method returns a "zero-indexed" number. So, it returns the number 9 for the 10th month. setDate() doesn't set the date, it sets the "Day of the Month". The name of that method is misleading.
Documentation - setDate()
So, the last two parameters that you are using in setDate() are doing nothing. You are setting the day of the month to 9.
If you want to set multiple date parameters at the same time, you need to use the new Date() method:
var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
The month parameter accept values from 0 to 11, 0 is Jan and 11 is Dec
Date Reference

How to concatenate the date in datenum with the year in MATLAB

I need to get the payment dates of a bond. The payments dates are quarterly. I have already set up the date in a cell. But I need to concatenate it with the particular year, which I am not sue how to.
EffectiveDate = datenum('15/05');
I need to concatenate it with the year like 2012.
What i Tried:
join(EffectiveDate,year(datenum('15/05/12'))
EffectiveDate + year
Both didn't give me a correct answer.
How do i do it? Need some help on this. Thanks.
If all values are given as strings:
date = '15/05';
year = '2012';
fullDate = [date,'/',year]; %String concatenation
now you can convert to serial form using datenum:
sDate = datenum(fullDate,'dd/mm/yyyy');
Hope this is what you asked for

Crystal Date Parameter for last year

I have tried using this formula with a date parameter. It works for the other 11 months but not the 12th month. Could some one please let me know what additional code I need to add to the formula.
If {?End Date} = 12/14/13
I want the formula to = 12/31/12
This is what I have been using to make it work for the other 11 months.
Date(year({?End Date})-1, month({?End Date})+1,1) - 1
I receive an error that the month needs to be 1 - 12.
Any suggestions will be greatly appreciated.
Thanks
This will give you the last day of the month of the previous year:
DateAdd("m", 1, DateTime( Year({immaster.timestmp})-1, Month({immaster.timestmp}), 1, 0,0,0 )) - 1
Try this.
CDate(Year(DateAdd ('yyyy',-1,CurrentDate)),Month(DateAdd ('M',0,CurrentDate)),31)