Question : Check Date against database date range values

I am pulling in a order start date and order end date to create an ordering window. I need to check that today's date falls within this defined window. It works to find out if the date is equal to or after the start date but not if it is before or after the end date of the window.

The code below displays:

9/22/2008 9/1/2008 10/5/2008

Response.Write(Format(Date.Now, "Short Date") & " " & Format(dr.Item("order_start"), "Short Date") & " " & Format(dr.Item("order_end"), "Short Date"))

It works if I don't check against the end date. I broke it out into an If and sub If statement with the same result. I am sure its some stupid error on my part.

It keeps going to the else when I know the dates are correct. I need to provide a link when the current date falls between the start and end dates.
Code Snippet:
1:
2:
3:
4:
5:
If Format(Date.Now, "Short Date") >= Format(dr.Item("order_start"), "Short Date") AND Format(Date.Now, "Short Date") <= Format(dr.Item("order_end"), "Short Date") Then
            OrderText = "Order"  
        Else  
            OrderText = "The current date does not fall within the ordering window for your state."  
        End If

Answer : Check Date against database date range values

You are comparing String values, not the actual DateTime values, that is why. Use DateTime comparison, instead of String comparison.

@elimesika,

"&&" is a C# operator. In VB.NET, it is "And" or "AndAlso"
Random Solutions  
 
programming4us programming4us