How can I output a date minus 3 hours? Example:
BookDate = 8/4/2014 9:00:00 PM
DesirebleDate = 8/4/2014 6:00:00 PM
Tried DesirebleDate = DateDiff("h", BookDate , -3) but it is outputing the amount of hours. Thanks.
DesirableDate = DateAdd("h", -3, BookDate)
Should set DesirableDate to 3 hours earlier than BookDate. DateDiff gives the difference between two dates, which is why you are getting the 3...
Related
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 stuck on my query attempt. I have a table that lists test results with their dates. I need to run a query to return the highest weekly average for a particular month.
I have the first part figured out:
SELECT Effluent BOD5, WEEK(Date)
FROM bod
WHERE YEAR(Date) = 2020 AND MONTH (Date) = 4
ORDER BY WEEK(Date)
Returns:
Effluent BOD5 / WEEK(Date)
10 14
14 14
9 15
6 16
7 16
11 17
8 17
I need to get the result of 12 (which is the highest weekly average (week 14).
Any help would be great![enter image description here][1]
I messed around with this and figured it out! Here is what I used:
SELECT max(Total)
FROM
(SELECT week, avg(test) AS Total
From
(SELECT Effluent BOD5 test, WEEK(Date) week
FROM bod
WHERE YEAR(Date) = 2020 AND MONTH(Date) = 4
ORDER BY WEEK(Date),Effluent BOD5 desc)ab
GROUP BY week)ac
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 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))
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))