I want to add months with last day in current date by using
=dateadd(dateinterval.month, +4, DateAdd("d",-(Day(today)), Today))
expression.
output is
current_date = 12/02/2014
finish_date = 03/30/2014
The problem is that finsih_date month is 03(March) and last day of March is 31 but my parameter showing 30.
It may look like:
=DateAdd("d", -1, DateSerial(DatePart("yyyy", finish_date), DatePart("m", DateAdd("m", 1, finish_date)), 1))
For every day in a given month it calculates the last day of the given month. So for 03/30/2014 you would get 03/31/2014.
Calculation works like: Build new date which is set to the first day of the following month of a given date. Substract 1 day. Which is the last day of the month before. As we added 1 month it is the last day of the month of the given date.
Edit
Code with finished_date = TODAY + 4 Month (finished_date + 1 so it is TODAY + 5)
=DateAdd("d", -1, DateSerial(DatePart("yyyy", DateAdd("m", 5, TODAY())), DatePart("m", DateAdd("m", 5, TODAY())), 1))
Related
I need to handle specific scenario in StorProc where I need to do date calculation excluding Sat & Sun. Weekends are holiday I need to handle the data within working days.
I have implemented below code
if (purchase_date = (trunc(sysdate)-2) or purchase_date = (trunc(sysdate)-1)) Then
specific operation
As I have to exclude Sat & Sun by above implementation is giving wrong results obliviously . For example if today is Monday it has to give me back the date of Friday, my implementation is giving me Saturday or Sunday. I need to calculation with dates for weekdays only. Any help would be appreciated.
Thanks
To compare it to the previous week day, you can use:
IF purchase_date = TRUNC(SYSDATE)
- CASE TRUNC(SYSDATE) - TRUNC(SYSDATE, 'IW')
WHEN 0 THEN 3
WHEN 6 THEN 2
ELSE 1
END
THEN
-- Do something
NULL;
END IF;
TRUNC(date_value) - TRUNC(date_value, 'IW') will count the number of days since the start of the ISO week (which is always midnight on Monday).
Note: Do not use TO_CHAR(date_value, 'D') in an international setting as it will give a different result depending on which country you run it in (the week starts on Friday in Bangladesh, Saturday in some Middle-Eastern countries, Sunday in America and Monday in most of Europe).
I need help on developing the expression for a parameter. What i need is:
That the report gives me data of the day before when it´s Tuesday, Wednesday, Thursday and Friday, and when it´s Monday that it gives me the data of the 3 days before (of Friday, Saturday and Sunday). How can i put that in an expression of the Parameter?
I usually have the date parameter that checks the current date and if it's Monday, subtract the extra two days.
=TODAY.AddDays(0 - IIF(TODAY.DayOfWeek.ToString = "Monday", 3, 1))
Then the query would use this as the starting date range and yesterday as the end.
WHERE MY_DATE BETWEEN #START_DATE AND CAST(GETDATE() - 1 AS DATE)
If the Date field has a timestamp then you'd need to convert that to a date.
WHERE CAST(MY_DATE AS DATE) BETWEEN #START_DATE AND CAST(GETDATE() - 1 AS DATE)
I am having issues getting the last day of month on my report.
I used the add month function to add a moth but it kept on giving me the first day of the next month. I only want the last day of the month as my end date and not the first day of the next month.
To get the last day of the current month enter the following Javascript:
now = new Date();
new Date (new Date(now.getFullYear(), now.getMonth() +1 , 1) - 1);
There is 2 dates column one is from date and second is to date .. and i want to get month difference from these two dates
like if
from date to date month difference
01-02-2019 02-02-2020 13
here 02 (feb) month 2019 till 02 (feb) moth 2020 so this means total 13 months covered..
i tried this but this shows wrong results
month(from date) - month(to date)
and i also try this
month([from date] - [to date])
I've been using the code below for this case.
It basically converts both dates to months and returns the difference.
First the Year component of the date is "converted" to months (year([to date]) * 12 part) and second adds the month number of the date (month([to date])
Num (
( (year([to date]) * 12) + month([to date]) )
- ( ((year([from date]) * 12) + month([from date])) ) + 1
)
UPDATE:
below is a screenshot of the result table with 2 expressions - including the +1 and excluding it. Depends how you want to calculate the full months +1 will "include" the last month as well
I want to get the previous month total day count
Code
Dim period as string
period = '01/2011'
totdays = DateDiff("d", txtPeriod, DateAdd("m", 1, txtPeriod))
'this will give the totaldays of the month...
But i want to get total days of the previous month
User will type current month only, but code should validate previous month
Expected Output
If period = '02/2011' means then it should display 31 days 'January
If period = '03/2011' means then it should display 28 days 'February
How to do this...
Any Help
This worked fine for me. Also, why do you have a variable period, but use txtPeriod in your calculations?
Dim dt As Date
Dim DaysInMonth As Integer
dt = CDate(txtPeriod.Text)
dt = DateAdd("m", -1, dt)
DaysInMonth = DateDiff("d", dt, DateAdd("m", 1, dt))