I am trying to display a message based on a date range. If it falls between the BeginDate and EndDate then the date should be display and if the date falls on 10-09-2017 then another message should be displayed, otherwise then it should display the date. This seems to fail and go directly to the else statement. My eyes are not picking up the error. How can something get displayed between a date range in VBScript.
<%
Dim DateT
Dim BeginDate
Dim EndDate
BeginDate = Day("2017-05-26")
EndDate = Day("2017-11-04")
DateT = Day(Date)
If BeginDate >= DateT =< EndDate
THEN response.write(DateT)
ElseIF BeginDate = Day("2017-10-09")THEN
response.write(DateT)
Else
response.write(DateT)
End If
%>
I believe your syntax is incorrect and your logic is overcomplicated.
Not exactly sure of the syntax here or the correct date format but I added some response.write for you to check (which should have been your first stop)
Your logic is overcomplicated because the only time it doesn't display the date is when it matches that special date..
Dim DateT
Dim BeginDate
Dim EndDate
BeginDate = CDate("2017-05-26")
EndDate = CDate("2017-11-04")
DateT = Date()
' remove these when you're finished debugging
response.write(BeginDate)
response.write(EndDate)
If BeginDate = CDate("2017-10-09")THEN
response.write("Another message")
Else
response.write(DateT)
End If
Related
Date format Shows Invalid Date With Custom Date. When I use 'Date' instead of "25th May" it shows yesterday's Date.
function GetYD()
Dim dt, yesterday
dt = DateAdd("d", -1, "25th May")
yesterday = Right(Year(dt),2) & Right("0" & Month(dt),2) & Right("0" & Day(dt),2)
msgbox yesterday
GetYD = yesterday
end function
Be sure to feed it a string that can be parsed. Always use digits if possible, and you did not even specify a year.
The format yyyy-mm-dd would probably work best, as it is (both to humans and to computers) totally un-ambiguous. So try it using
DateAdd("d", -1, "2017-05-25")
I have to make a report that will execute automatically several times, every day, with different settings. The report selects records between two dates. Now, the client wants to be free to define, in a text or excel file, the dates that will run each report. For example, every day I want to run the report for that day, and for that same day the previous year, and for the same day the previous week, and for the previous week, and for the next month of the previous year. Then on the first of every month, the whole previous month, etc. I think you get the gist.
My question is: Is there any established way of doing this? Some text encoding for offsets of dates? I've looked and nothing appears. However, it doesn't seem an outlandish proposition. I suppose the situation has happened before. I wouldn't like to reinvent the wheel. If, however, there is nothing, any idea would be welcome :-)
OK, so I did it myself, no free lunch this time :-) The format I chose is a string like:
+1W,fW,-1D (That would be the next week, first day of that week, then one day before that)
Separator is comma, keys are D for day, W for week, M for month, Y for year, F for first, L for Last (all keys can be lower or upper case). The format ignores whitespace, but the last non-whitespace character must be a key. Only integer offsets allowed.
I give my first implementation of a VBA function that interprets a text offset. It seems to work, although little testing done yet.
Well, that's all, for posterity.
Public Function GetDateFromOffset(fecIni As Date, sDif As String) As Date
Dim sArr() As String, ii As Integer, fRes As Date
fRes = fecIni
sArr = Split(sDif, ",")
For ii = LBound(sArr()) To UBound(sArr())
fRes = ApplyOneOffset(fRes, sArr(ii))
Next ii
GetDateFromOffset = fRes
End Function
Public Function ApplyOneOffset(fecIni As Date, sDif As String) As Date
Const C_DAY As String = "D", C_WEEK As String = "W", C_MONTH As String = "M", C_YEAR As String = "Y"
Const C_FIRST As String = "F", C_LAST As String = "L"
Dim iDesp As Integer, sDesp As String, fRes As Date
sDesp = UCase(Right(sDif, 1))
sDif = Trim(UCase(Left(sDif, Len(sDif) - 1)))
Select Case sDesp
Case C_DAY
If (IsNumeric(sDif)) Then
fRes = DateAdd("d", CInt(sDif), fecIni)
End If
Case C_WEEK
If (sDif = C_FIRST) Then
fRes = dhFirstDayInWeek(fecIni)
ElseIf (sDif = C_LAST) Then
fRes = dhLastDayInWeek(fecIni)
ElseIf (IsNumeric(sDif)) Then
fRes = DateAdd("ww", CInt(sDif), fecIni)
End If
Case C_MONTH
If (sDif = C_FIRST) Then
fRes = dhFirstDayInMonth(fecIni)
ElseIf (sDif = C_LAST) Then
fRes = dhLastDayInMonth(fecIni)
ElseIf (IsNumeric(sDif)) Then
fRes = DateAdd("m", CInt(sDif), fecIni)
End If
Case C_YEAR
If (sDif = C_FIRST) Then
fRes = DateSerial(YEAR(fecIni), 1, 1)
ElseIf (sDif = C_LAST) Then
fRes = DateSerial(YEAR(fecIni), 31, 12)
ElseIf (IsNumeric(sDif)) Then
fRes = DateAdd("yyyy", CInt(sDif), fecIni)
End If
Case Else
fRes = fecIni
End Select
ApplyOneOffset = fRes
End Function
Similar to this question
When querying CalendarView, it doesn't seem to support Start and End ( so they don't get translated into the correct values).
My code returns an error because i didn't include the parameters.
Is there any way to add these parameters through the OutlookServicesClient?
My current code looks like this:
Dim calendarView = exClient.Me.CalendarView
' For Each Attendee In AttendeesFilter.Split(New Char() {Char.Parse(";")}, StringSplitOptions.RemoveEmptyEntries)
' calendarView.Where(Function(dl) dl.Attendees.Any(Function(el) el.EmailAddress.Equals(Attendee)))
' Next 'Office365 doesnt seem to filter on attendees
startDate = DateTime.Now.AddMonths(-1)
endDateTime = DateTime.Now
If startDate.HasValue AndAlso endDateTime.HasValue Then
calendarView.Where(Function(dl) dl.Start.Value <= startDate.Value AndAlso dl.End.Value <= endDateTime.Value) 'doesnt seem to filter on dates
End If
The exact error i receive is :
Type: Microsoft.OData.Core.ODataErrorException
Message: This request requires a time window specified by the query string parameters startDateTime and endDateTime.
Although i can't seem to find a proper way on how to add the time window :s
There is a function:
exClient.Me.Calendar.GetCalendarView(startDateOffset, endDateOffset)
This filters between start and endDate instead of adding it to the Query
You can get a CalendarView as follows:
var eventResults = await exClient.Me.Calendar
.GetCalendarView(startDateTime,endDateTime)
.Take(10)
.ExecuteAsync();
I have a function in my VBA code which sets a specific Date format for a textbox.
This is my code to verify the Date is in the correct format:
Function CheckDate(DateStg As String) As Boolean
If DateStg = "" Then
' Accept an empty value in case user has accidentally moved to a new row
CheckDate = True
lblMessage.Caption = ""
Exit Function
End If
If IsDate(DateStg) Then
CheckDate = True
lblMessage.Caption = ""
Else
CheckDate = False
lblMessage.Caption = "Sorry I am unable to recognise " & DateStg & " as a date."
End If
End Function
In addition to checking if the date in the textbox is an actual date, I need to verify that the textbox date is not less than the current date minus 1 month, and. Also, I would like to verify that the date is not more than the current date plus 1 year.
So:
DateStg > Today - 1 month
DateStg < Today + 1 year
Thanks for your help in advance.
You have a few functions you can use:
''Assume date is not good
DateOK=False
If IsDate(DateStg) Then
If DateStg > dateAdd("m",-1,Date()) _
And DateStg < dateAdd("m",12,Date()) Then
''Date is good
DateOK=True
End If
End if
For the most part, textboxes can be set to only accept dates and you can set validation rules to check the range, so code may not be necessary.
If you just want to check the date, you can use the DateAdd-function to get the dates to compare:
'Subtract a month from today and return it as a string
Format(DateAdd("m", -1, Now), "yyyy-mm-dd")
'Add a year to today and return it as a string
Format(DateAdd("yyyy", 1, Now), "yyyy-mm-dd")
I have this dates into my DGV:
14/06/2012
15/07/2012
16/07/2012
17/07/2012
I set the Filter to this: ([supplier_invoice_date] >= '13/07/2012') AND ([supplier_invoice_date] <= '17/07/2012')
The Filter return this (All the dates):
14/06/2012
15/07/2012
16/07/2012
17/07/2012
Another test:
Filter: ([supplier_invoice_date] >= '15/07/2012') AND ([supplier_invoice_date] <= '17/07/2012')
Result:
15/07/2012
16/07/2012
17/07/2012
Filter: ([supplier_invoice_date] < '17/06/2012')
Result:
14/06/2012
15/07/2012
16/07/2012
I think it is only taking the days and does not take months.
Here is my code:
Dim dt As New DataTable
Dim suppliersinvoices_data_query As String = ("DATE_FORMAT(MIN(supplier_invoice_date), '%d/%m/%Y') AS supplier_invoice_date, ...")
Dim invoice_objDataAdapter As New MySqlDataAdapter(suppliersinvoices_data_query, objConn)
invoice_objDataAdapter.Fill(dt)
Dim MyFilter As New DataView(dt)
MyFilter.RowFilter = "([supplier_invoice_date] >= '13/07/2012') AND ([supplier_invoice_date] <= '17/07/2012')"
invoicesresults_datagrid_search_supplierinvoice.DataSource = MyFilter
This is the DataView.RowFilter syntax for Dates:
dataView.RowFilter = "supplier_invoice_date >= #2012-07-13#"
But you could also using Linq-To-DataSet. I assume that the actual datatype of the field isStringinstead of Date, so you need to parse it to Date first:
Dim startDate = New Date(2012, 7, 13)
Dim endDate = New Date(2012, 7, 17)
Dim invoiceDate As Date
Dim filtered = From row In dt.AsEnumerable()
Where Date.TryParse(row.Field(Of String)("supplier_invoice_date"), invoiceDate) _
AndAlso invoiceDate >= startDate AndAlso invoiceDate <= endDate
Dim tblFiltered As DataTable = filtered.CopyToDataTable()
It looks like you are converting the dates to strings in order to format them. Try to avoid that, and just let the grid use the date value it is getting from the data source.
If you want to format the date of the DataGridView control, try it like this:
dgv1.Columns("YourDateColumn").DefaultCellStyle.Format = "dd/MM/yyyy"
Then you can use real dates to filter the data:
MyFilter.Filter = String.Format("[supplier_invoice_date] > '{0}'", _
New DateTime(2012, 7, 1))