I need to compare a date v. "Today" in a MM/YY format and then if true it will execute the rest and if not it will be blank. This is what I have so far but I get the "'Interger' to type 'Date' is not valid...
=IIF(Format(Month(10) & Parameters!Year.Value, "MM/YY") < Format(Today,"MM/YY"),
IIF(Fields!Milestone.Value="Average Number of Days Milestones were Early",
FormatNumber(Fields!Oct.Value,0), IIF(Fields!Oct.Value = 0, "",
FormatNumber(Fields!Oct.Value,0))),"")
I really appreciate any help. Thank you
I kept playing around and got it to work
=IIF(FormatDateTime(CDATE("11" & "/" & Parameters!
Year.Value),DateFormat.ShortDate) < FormatDateTime
(Today,DateFormat.ShortDate),IIF(Fields!Milestone.Value="Average Number of Days Milestones were Early",
FormatNumber(Fields!Oct.Value,0), IIF(Fields!Oct.Value = 0, "",
FormatNumber(Fields!Oct.Value,0))),"")
Related
Can someone advise, please?
I have used DateSerial, DateValue with mixed results, also Format(... doesn't work in this case.
When I use DateAdd("d", 1, DateValue(x.Value))
06/05/2021 20:20:20
is changed to
05/07/2021 20:20:20
All I need is this 06/05/2021 20:20:20 to be changed to this 07/05/2021 20:20:20
FYI if it helps the format of my cells is as follows:
Try this and swap dd/mm to mm/dd (the format will remain dd/mm/yyyy):
Format(DateAdd("d", 1, cel.Value), "mm/dd/yyyy") & " 18:59:59"
If you wish to use DateAdd, and your value is a true date value (not text), use:
DateAdd("d", 1, x.Value)
This will not alter a time part. If x is 2021-05-06 20:20:20, result will be:
`2021-05-07 20:20:20`
If x is 2021-05-06 18:59:59 you can add one hour:
DateAdd("h", 1, x.Value)
for the result: 2021-05-06 19:59:59
just x.value + 1 it'll get that it's a date and add one day
I have a small code that gets the Day Name of the Dates listed in Excel. But the problem is, it's not getting the right Day Name(e.g. Tuesday).
For Example:
sDayName = Format(Day(11/1/2016), "dddd")
Then the output produces an incorrect Day Name which is:
sDayName = "Sunday"
when it's supposed to be "Tuesday".
Thanks for the help guys.
For your specific request, assuming your date string is formatted as your regional setings:
sDayName = Format("11/01/2016", "dddd")
If you want the weekday for today:
sDayName = Format(Date, "dddd")
If you want the weekday for any date in any regional settings
sDayName = Format(DateSerial(2016, 11, 4), "dddd")
'change 2016, 11, 4 for your year, month, day values
:)
WEEKDAY Function can be used on this topic and in Vba Codes . For example:
Label2.Caption = WeekdayName(Weekday(TextBox2, 0), False, 0)
I used this function in when I created userform about date entry to active cell.
i use the answer kadrleyn wrote.
But you have to pay attension that the string returned from
WeekdayName(Weekday(TextBox2, 0), False, 0)
is not trimmed so if you want to use it in if statement you have to use trim function.
ps. i could not add comment to his/her answer because of my reputation.
hi guys i have the expression below which i am trying to use to concatenate some int param values and one int value.
In the end i want a date for the last day of the month based on what the user selected.
Spent all day on this, couldn't find anything in stack.
=Parameters!Year.Value & 10 & IIF(LEN(Parameters!Period.Value) <= 1,0 &
Parameters!Period.Value,Parameters!Period.Value)
Supposing that "Period" is the month, you are most likely looking for something like this:
=DateSerial(Parameters!Year.Value, Parameters!Period.Value, 1).AddMonths(1).AddDays(-1)
I have a two dates in excel "1/2/2016 01:56:05" and "8/3/2016 06:21:46". How do I calculate the time difference between them in a format of days and hours?
Thanks!
Try this to include the spelled out hours and minutes:
=INT(A2-A1) & " days, " & TEXT(A2-A1,"h "" hours, ""m "" minutes""")
Note that since the m comes immediately (ignoring the separator text in quotes) after the h it will be interpreted as minutes and not months
I prefer to work with dates as decimals. It looks cumbersome, but I'm much happier knowing what it's doing.
What I would usually do is to have A1-A2 in cell A3, then work out the component parts separately:
Days: =INT(A3)
Hours: =INT((A3-INT(A3))*24)
Minutes: =INT(((A3*24)-INT(A3*24))*60)
Or if you wanted to do it all in one formula:
=INT(A3)&" days, "&INT((A3-INT(A3))*24)&" hours, "&INT(((A3*24)-INT(A3*24))*60)&" min"
or without using A3
=INT(A1-A2)&" days, "&INT(((A1-A2)-INT(A1-A2))*24)&" hours, "&INT((((A1-A2)*24)-INT((A1-A2)*24))*60)&" min"
It's not the prettiest or most efficient method but you can see how the times are calculated this way.
Assuming the dates are in cells A1 and A2, this will produce an answer with minutes as well in d:hh:mm format.
=INT(A2-A1) & ":" & TEXT(A2-A1,"hh:mm")
Drop the :mm if you don't need minutes.
If you want text:
=INT(A2-A1) & " days, " & TEXT(A2-A1,"h") & " hours"
If you want text with minutes:
=INT(A2-A1) & " days, " & TEXT(A2-A1,"h"" hours, ""m"" minutes""")
Using double quotes alongside each other "escapes" the quote itself and allows the extra text to appear in the string. As Ron stated in his answer, the m following an h in the same format string indicates minutes, so you can save an extra A2-A1 calculation by putting both in a single format.
I'm having big problems doing operation with the date in Excel VBA.
I have a form that has a textbox where the user will enter the date. The problem is that he may enter it in different formats (eg, 1.08.2011 for 1st of August, or 8/1/11 for the same day). Now what I want to do is to subtract some days from that date that he enters in the TextBox. I had to success so far and I don't know how to do it.
I tried something like this
Format((Format(Me.datalivrare.Value, "dd.mm.yyy") - 4), "dd.mm.yyyy")
Where datalivrare is that textbox where the user enters the date and 4 is the number of days I want to subtract from that date... and I want the format to always be dd.mm.yyyy no matter what they enter in that textbox.
I suggest looking at the DateAdd function for VBA
http://www.techonthenet.com/excel/formulas/dateadd.php
http://office.microsoft.com/en-us/access-help/dateadd-function-HA001228810.aspx
You could do the following:
Format(DateAdd("d", -4, CDate(Me.datalivrare.Value)), "dd.mm.yyyy")
First cast to Date, then subtract days, then format appropriately:
Format(DateAdd("d", -4, CDate(Me.datalivrare.Value)), "dd.mm.yyyy")
the best to add and substract from dates on vba is dateadd() (with negative number for substractions)
also, in your example code there's a missing y on the format string (it accepts 1, 2 or 4 y, only)
It is important to check if the user entered a value that VBA can interprit as a date so first you should:
If isDate(Me.datalivrare.Value) Then
str_Date = Format(DateAdd("d", -4, CDate(Me.datalivrare.Value)), "dd.mm.yyyy")
Else
MsgBox "Not a valid date value", vbCritical + vbOkOnly, "Invalid Entry"
End If
I think bluefeet's answer had the most information so far and I borrowed the use of DateAdd and CDate.
Just a simple answer, as many aren't using the OP's code.
Eg: Minus 4 days
https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/dateadd-function
Sub DateTest()
Dim DateVar As Date
DateVar = DateAdd("d", -4, Date)
Debug.Print DateVar
End Sub