MomentJS next 15th - angularjs

Im developing a simple application that show the daily budget until the next payment. For that I'm using momentJS.
The problem is that the logic in my application is wrong. Im, first finding what day is it, then I find the first day of the this month (date(1)), then I sum 1 month and 14 days. But whenever its the next month (as right now -02/12), it will, of course tell me that the next 15th is in February.
Long story short, how do I find the next 15th using moment?
Here is my application:
$scope.nextDate = moment().date(1).add(1, "months").add(14,"days"); //calculate when is the next 15th
$scope.difference = Math.floor(moment.duration($scope.nextDate.diff($scope.today)).asDays());
Thanks in advance!

Use a simple condition in the add method when calculating the nextDate.
$scope.nextDate = moment().date(1).add((moment().date() > 14 ? 1 : 0), "months").add(14,"days");
This will either add 0 or 1 months to your calculation based on the condition if current date is larger than 14 (modify to 15 if you want to count "next" 15th as today when it's actually 15th)

Related

How to get a YTM calculation instead of YTD in Google Data Studio

I have an earnings table in my Google Data Studio report from January 21 - YTD.
But what i want is a table that shows me YTM (so this year until last month) Jan-21 til Sep-21 and that dynamicly on 1st Nov, Okt-21 is added to the table, and on 1st dec Nov-21
is added etc.
Because the Total YTD value is other wise too high, due to cost being booked at the end of the month and earnings through the month.
Filters wont let you do it dynamicly,
date range filters same,
always possible to do it manualy with date range but this i cannot ask from my client.
any suggestions??
Kind regards
I found the answer,
i left the question for when someone else wants to do it,
it is actualy simpel fixed by using advanced date filter and then leaving the start date on 1-jan, and end date to today minus 1 month.
this gave me the exact result i needed yt last month

why I get display next month instead of current month

Why I see this page is in wrong month, it should init to show August instead of September , I am from cambodia
http://react-day-picker.js.org/examples/months-initial
From MDN docs:
The argument month is 0-based. This means that January = 0 and December = 11.
var startOfYear = new Date(2017,0)
console.log(startOfYear.toLocaleString())
Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
I've been looking around your site for a couple of minutes, and I noticed that the month number is capped at 11 (so December equals 11). That must be because of common code basics, where the first item of an array starts with an index of 0 (= January). Your timezone has nothing to do with the site so don't worry ! (tested from France)

SSRS Date Expression stopped working

I hope someone can share their experience with me. I've used the following ssrs expression to default a SSRS report parameter to the last day of the current month for months without issue:
=DateAdd(ā€œdā€, -1, DateSerial(Year(Now()), Month(Now()), 1))
This morning instead of returnng 3/31/2016, the expression is stuck on 3/29/2016. Can anyone help me understand why this happened?
You are substracting one day to the first day of the current month.
You have to get the first day of the next month and substract one day.
=DateAdd("d", -1, DateSerial(2016, Month(Now.AddMonths(1)), 1))
It returns 3/31/2016
Let me know if this helps.
The expression you show will give the last day of the previous month, not the last day of this month.
You want to do date arithmetic rather than build dates from scratch. Think about what will happen in December if you are using the current year but adding a month to find the month you need.
The safest way to get the last day of the current month would be to calculate the first day of this month, add one month then subtract a day:
=DateAdd(DateInterval.Day, -1, DateAdd(DateInterval.Month, 1, DateAdd(DateInterval.Day, 1-Day(Today), Today)))
If what you actually want is the last day of the previous month, then that is simple:
=DateAdd(DateInterval.Day, 0-Day(Today), Today)

How to get the last 7 Days Dates in SSRS

I'm having a Report where I need to display the dates of last 7 days.
As shown below
Sun, Mon etc... are hard coded and the Dates are written in Expression
For example,
If today is Wednesday I need to show the Dates till last Tuesday.
If it is Thursday I need to show the Dates till last Wednesday.
How to retrieve the dates information and display below the corresponding days.
To get last seven days date you can do something like below in each expression,
To get Days in Header
=WeekdayName(weekday(Parameters!TodaysDate.Value)) --Tuesday
=WeekdayName(weekday(DateAdd("d",1,Parameters!TodaysDate.Value))) --Wedneday
Same for others too... Just by increment/decrement by 1.
To get Days Date in Data
=Format(Parameters!TodaysDate.Value,"dd-MMM-yyyy")
=Format(DateAdd("d", 1, Parameters!TodaysDate.Value),"dd-MMM-yyyy")
Same for others too... Just by increment/decrement by 1.
Here TodaysDate would be parameter date or Now() Date.
I have given demo of incremental one, you can change it as per your condition. I think you need to use decrement here. So Instead of 1 you need to use -1.
This will give you output like below,

Dateadd returning the wrong days in the month

I have a stored procedure that runs to pull data for sales in a given month.
It does not return 31 days on months that have 31 days.
I need some help understanding the breakdown of the following string
(dateadd(dd,-(datepart(dd,getdate())),CONVERT(CHAR(8),GetDate(),112)))+'23:59:59')
I understand that CONVERT(CHAR(8),GetDate(),112) is taking the system date and converting to YYYYMMDD and that datepart(dd,getdate()) takes the system date and takes just the day part, but I cannot decipher the entire string.
There is a issue with the expression you have given. The bracket after 23:59:59 does not have a opening brace.
However what the expression intends to do is:
(datepart(dd,getdate())) is getting the the current date's day part
CONVERT(CHAR(8),GetDate(),112)) is getting current date in YYYMMDD
(dateadd(dd,-(datepart(dd,getdate())),CONVERT(CHAR(8),GetDate(),112))) is subtracting the day part from today's date (see the negative sign).
Thus it is trying to get the first day of the current month. In case the result of the above expression crosses the last day of the previous month, it adds 23 hours 59 minutes.
The logic was probably intended to get the last day of the previous month. This adding of ~24 hours is creating confusion.
This will help you out:
declare #First datetime = dateadd(month,datediff(month,0,getdate()),0)
declare #Last datetime = dateadd(second,-1,dateadd(month,datediff(month,0,getdate())+1,0))
#First checks for the number of months from ZERO to NOW, then adds that number of months to ZERO to give you the first moment of this month.
#Last works similarly, but adds one month to the number of months added to ZERO to give you the first moment of next month, then it subtracts 1 second from that date to give you the last second of the last day of this month.
If you need to go to MS, you can change the last bit to subtract 3 miliseconds instead of 1 second.

Resources