Is there a way to convert the below Excel formula to a query/criterion in Access?
L2 = Date
J2 = Another Date
Z1 = Todays Date
I think it is calculating the number of days in between two dates but not sure how to do this in an Access query.
IF((AND((L2<1),(J2>1))),(NETWORKDAYS(J2,$Z$1)-1),0)
As you may by now have gathered, the question does not really make sense. NETWORKDAYS does indeed calculate the number of “whole working days excluding weekends and any dates identified in holidays” between two dates (here whatever date is in J2 and whatever is ‘Today’/Z1) and IF makes that calculation contingent upon the result of the AND function being TRUE. The AND function results in TRUE provided both the ‘date’ in L2 is before 1/1/1900 and the date in J2 is after 1/1/1900 (because to Excel 1/1/1900 is Day 1 where dates are concerned [unless one opts for the 1904 date system]).
But Excel does not recognise a date before Day 1, whether a negative number or a decimal number. For example Day 1.5 is noon on 1/1/1900 whereas in the same format Day 0.5 shows as 0/1/1900.
So in essence, L2 is not a date of any real use to the formula, hence I believe why no answer yet to your question. But this is too long to fit in a comment hence my answer: “No.”!
Set a reference to Excel.
Option Compare Database
Private Sub Command2_Click()
MsgBox GetNetWorkDays(#1/29/2017#, #2/8/2017#)
End Sub
Function GetNetWorkDays(startDate As Date, endDate As Date) As Integer
GetNetWorkDays = WorksheetFunction.NETWORKDAYS(startDate, endDate)
End Function
Put the button on a Form and click the button!
If you want to calculate number of days between days than you can use below built in function "DateDiff" which will solve it out. Datediff("D",,)
Ex. Datediff("D",L2,Z1)
Related
I'm struggling to make a formula work in excel.
My case : I have data in m/d/yyyy h:mm AM/PM format on E col.
I have data that goes to the next day post midnight. I'm looking to create another column lets say F where I want to check for data between time 5:30pm to next day 5:30am and return date in m/d/yyyy(col F)
Example :
Let's say a job request came in at 3/21/2021 4:30am, I want it to return 3/20/2021 on col F (previous date)
This is required due to different timezone and unfortunately the timezone cannot be altered on the data.
If it's really true that your data are in "m/d/yyyy hh:mm PM format" then this formula will deduct 8 hours from the value found in E4 and return a true date.
=DATE(RIGHT(LEFT(E4,FIND(" ",E4)-1),4),LEFT(E4,FIND("/",E4)-1),MID(E4,FIND("/",E4)+1,1+ISERROR(FIND("/",MID(E4,LEFT(E4,FIND("/",E4)-1),2)))))+TIMEVALUE(MID(E4,10,10))-(8/24)
A "True" date is a number which takes its display format from the cell format you set, meaning the "data" are different from the display. A "Fake" date (my expression) is a text string that looks like a date but is unsuitable for calculations because it's not a number. The "data" underlying a fake date are identical to the display. My above formula spends 95% of its effort on converting the fake date into a true one and is likely to earn your comment that it "doesn't work" because it returns a number. If so, don't comment. Set the cell format to the kind of display you want.
Of course, if E4 has a true date the effort can be reduced and the formula you seek would be simply
=E4-(8/24)
This is because in Excel dates one day has a value of 1. Therefore 1 hour = 1/24 and 8 hours = 1/24*8 or 8/24. Change the number of hours as desired, add or subtract them from the original as needed.
BTW, if your original data are really text (fake dates) do consider converting them to true dates using the 95% part of my first formula and then processing them as true dates. As you see, there is no advantage in keeping fakes around.
I'm working with a workbook that has dates with time included in 2 worksheets. When a variable is set to the date in worksheet A, it'll look for it in worksheet B and retrieve the row number by using a second variable.
The issue I'm having is that when variable 1 and 2 match (i.e. the date exists in worksheet B), it doesn't recognize them as being equal. I stepped through the procedure to see if I could find out why they weren't matching and it turns out it's because the serial dates are slightly different.
44027.3333333325 and 44027.3333333333 for variable 1 and 2 respectively.
What do the last 2 numbers represent and how can I resolve this?
I've confirmed the cells have the same custom formatting and I have them "dimmed" as the same type (tried with both double and date). I need to keep the decimals for the time.
Thank you
As Scott Craner points out in the comments, the decimals represent the time down to a small fraction of second. To compare dates while ignoring the precise time, use the DateValue function; that way there is no need to apply rounding to your data.
Sub CompareTwoDates()
Dim Date_1 As Date, Date_2 As Date
Date_1 = 44027.3333333325
Date_2 = 44027.3333333333
If DateValue(Date_1) = DateValue(Date_2) Then
MsgBox "The dates are identical.", vbInformation + vbOKOnly, "Date Comparison"
End If
End Sub
More on the DateValue function here: DateValue function
The decimal portion of the Excel datetime value represents the time. The 0.0000000008 difference between your two values represents around 10 micro seconds, which is more precision than Excel is able to display in a standard date/time format. If you are only interested in precision to a second level, you could safely round the values to six decimals, which will still give you a time with precision better than 1 second.
I have got a start date and end date in this custom format
dd.mm.yyyy hh:mm in excel cells.
What i need is to fill specific row with dates incremented by half hour from start date to end date using VBA code. And i havent got any idea how to do this.
On web there are some examples with similar problems but with only months or only hours and those are dates format not custom.
You can do this with a simple formula.
Write your start date into cell A1
In A2 write =A1+(1/48)
Copy formula from A2 down
done.
How does this work?
Excel dates are represented as count of days since 1900. That means 1900-01-01 is the first day and represented by 1. All other dates are just the count of days since then. 1 represents one day. So since 1 day has 24 hours 1/48 represents half an hour.
The number format dd.mm.yyyy hh:mm how Excel shows the date is not relevant, because Excel only saves the value (amount of days since 1900) in the cell value.
So if you type the date of today into a cell 2018-10-11 Excel actually saves 43384 in the cell value (today it is 43384ᵗʰ day since 1900-01-01).
One option is to find the interval between start and stop point. Remember that excel dates that are actually dates and not strings are actually integers. The second thing to remember is time is the decimal part which represent fraction of a day. Test if your date (assuming it's in A1) is an actual date or a string with
=ISNUMBER(A1)
If that comes back TRUE you do not need to worry about converting your date. If it comes back FALSE, its actually a string and will need to be converted for excel to work with it.
Divide this interval by 30 minutes, or 30/60/24 to and add 1. This will tell you how many iteration you will need which you can put into a For loop
Start_Number = Range("A1")
End_number = Range(("A2")
Stamp = Start_Number
Interval_number = End_Number - Start_Number
Counter = integer of (Interval_number / (30/60/24))
For x = 1 to counter
write Stamp to cell
Stamp = Stamp + 30/60/24
Next x
Allternatively you could set up a while loop.
Do While datetime < Stop_Point
Write datetime to cell
Datetime=datetime + 30/60/24
Loop
Please note, not actual code but giving idea where OP had no idea where to start.
Is there any option to compare dates with Date format yyyymmddhhmmss with the current date?
Basically one of my external source have this type of date and I have to compare this date with the current date and check difference in between. I have tried to split those date with LEFT,MID,RIGHT functions, so basically, I have two columns - first with date, second with time, but I cannot find any option to subtract current date with date in column, because results are not coming correct.
Sample of date: 20161112203545
after splitting: 2016-11-12 20:05:45.
Any ideas?
Image produced below with formulas is self explanatory.
Your date :20161112203545 in D4
Formula to convert date in E4 :
=DATE(LEFT(D4,4),MID(D4,5,2),MID(D4,7,2))+TIME(MID(D4,9,2),MID(D4,11,2),RIGHT(D4,2))
Today's Date in F4 : =TODAY()
Formula to get date difference in days in G4 : =DATEDIF(F4,E4,"d")
EDIT
The alternative to Excel DATEDIF would be a User defined function (UDF) that internally uses the VBA DATEDIFF function:
This UDF accepts three parameters:
Start_Date: The days from which the period begins.
End_Date: It is the last date of the period that you wish to calculate.
Unit: It specifies the interval by which you want the difference. Here the unit accepts following values.
Value Description
YYYY Year
Q Quarter
M Month
Y Day of year
D Day
Public Function xlDATEDIF(Start_Date As Date, End_Date As Date, Unit As String) As String
xlDATEDIF = DateDiff(Unit, Start_Date, End_Date)
End Function
In this case usage will be, put formula in H4 =xlDATEDIF(F4,E4,"D")
HTH
Taking the date as
20161112203545 after splitting: 2016-11-12 20:05:45
Is going to cause you some issues as Excel assigns date values with a serial number, and it's going to throw that number off. You could use the =today() function and set it up where you have the date entered, say it is in cell A1, then =A1-today() (formatted as a number) should give you the difference in the amount of days.
Microsoft explanation of using Dates in Excel
i need an excel formula to calculate the total days remaining for a cell: end date minus todays date plus extension days(maybe 30-90 amount is in a cell) i have tried =days360(today's date,end date + number of extension days) in a different cell but it isn't giving me the correct total
It's giving me the wrong amount of days. I have a formula calculating my end date as well, is that causing a problem =SUM(start date+90+#of extension days)
One possible reason could be your usage of the DAYS360 formula. That uses a 360-day calendar and assumes all months are 30 days. Therefore if you are covering a range where this would have an effect, you will see a difference. For example, with the range 1/1/2013 to 6/1/2013, subtracting the two dates returns 31+28+31+30+31 = 151, compared to DAYS360, which returns 30*5 = 150.
Try just doing basic subtraction, which will also work on dates:
=<End Date> - TODAY() + <Extension>