Calculate last day of month
var month = 0; // January
var d = new Date(2008, month + 1, 0);
console.log(d.toString()); // last day in January
last day of month calculation
Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH);
This returns actual maximum for current month. For example it is February of leap year now, so it returns 29 as int
.
How do I get the last day of a month?
The last day of the month you get like this, which returns 31:
DateTime.DaysInMonth(1980, 08);
Quicksight: Aggregation Over Last Day of Month
i finally solve it like this using the posted formulas:
parseDate
(
concat
(
toString(extract("YYYY",addDateTime(1,"DD",addDateTime(1,"MM",truncDate("MM",date)))))
,"-"
,toString(extract("MM",addDateTime(1,"DD",addDateTime(1,"MM",truncDate("MM",date)))))
,"-"
,toString(extract("DD",addDateTime(-1,"DD",addDateTime(1,"MM",truncDate("MM",date)))))
)
,'yyyy-MM-dd')
And because current month have not ended so i don't have data for the the last day i use an ifelse like this:
ifelse(
parseDate(
concat(
toString(extract("YYYY",addDateTime(-1,"DD",addDateTime(1,"MM",truncDate("MM",date)))))
,"-"
,toString(extract("MM",addDateTime(-1,"DD",addDateTime(1,"MM",truncDate("MM",date)))))
,"-"
,toString(extract("DD",addDateTime(-1,"DD",addDateTime(1,"MM",truncDate("MM",date))))))
,'yyyy-MM-dd')
>= now()
,addDateTime(-1,"DD",now())
,parseDate(concat(toString(extract("YYYY",addDateTime(-1,"DD",addDateTime(1,"MM",truncDate("MM",date)))))
,"-"
,toString(extract("MM",addDateTime(-1,"DD",addDateTime(1,"MM",truncDate("MM",date)))))
,"-"
,toString(extract("DD",addDateTime(-1,"DD",addDateTime(1,"MM",truncDate("MM",date)))))
)
,'yyyy-MM-dd')
)
And finally i created de following calculated field:
sumIf(base,formatDate(date,'yyyy-MM-dd') = formatDate({fecha_last_day},'yyyy-MM-dd'))
The result:
The value related to the last day for each month, and for current month the last day with able data
How to find the last day of the month from date?
t
returns the number of days in the month of a given date (see the docs for date
):
$a_date = "2009-11-23";
echo date("Y-m-t", strtotime($a_date));
The last day of month from the last date with sales
The problem is caused by using dates from table T. Instead, you need to use dates from the calendar table, because list of dates for the time intelligence functions must be continuous.
Assuming you have a properly designed and connected calendar table 'Date' in your data model, change your DAX to:
LastDate =
ENDOFMONTH (
LASTNONBLANK (
Date[Date],
CALCULATE ( SUM ( T[Amount] ) )
)
)
ENDOFMONTH will use now a different table (Date), because LASTNONBLANK function will keep data lineage to it.
How to get the last day of the month?
calendar.monthrange
provides this information:
calendar.monthrange(year, month)
Returns weekday of first day of the month and number of days in month, for the specified year and month.
>>> import calendar
>>> calendar.monthrange(2002, 1)
(1, 31)
>>> calendar.monthrange(2008, 2) # leap years are handled correctly
(4, 29)
>>> calendar.monthrange(2100, 2) # years divisible by 100 but not 400 aren't leap years
(0, 28)
so:
calendar.monthrange(year, month)[1]
seems like the simplest way to go.
Calculating first and last day of month from a yearmon object
We can use
library(dplyr)
library(lubridate)
library(zoo)
df %>%
mutate(firstday = day(year_mon), last = day(as.Date(year_mon, frac = 1)))
Related Topics
Correct Way of Throwing Exceptions with Reactor
Peer Not Authenticated While Importing Gradle Project in Eclipse
Enhanced 'For' Loop Causes an Arrayindexoutofboundsexception
Time Complexity of Java's Substring()
Lambda Expression and Method Overloading Doubts
How to Sort Two Arrays in Relation to Each Other
Error:Java: Invalid Source Release: 8 in Intellij. What Does It Mean
Jbutton Actionlistener - Gui Updates Only After Jbutton Is Clicked
How to Deserialize Js Date Using Jackson
Generating a Random Number Between 1 and 10 Java
How to Disable Javac's Inlining of Static Final Variables
How to Convert Date in to Yyyy-Mm-Dd Format
Differencebetween 'E', 'T', and '' for Java Generics
Java - How to Receive Point Coordinates After Mouse Button Release (Jfreechart)