Following is the code is used
Dim FilterExpression As string
Dim oDate as DateTime
oDate=System.DateTime.Now
FilterExpression = " quot_date >= '" + oDate.ToString() + "'"
Before Assign oDate contains #2/10/2013 6:10:35 PM# this but when it assign to FilterExpression it becomes quot_date >= '10/02/2013 6:10:35 PM'
Date is changing his format
Any idea why?
Firstly, that’s VB rather than C#.
Secondly, the value of
oDateis a value of typeDateTime. Whereas#2/10/2013 6:10:35 PMis a VB literal of typeDateTime, that’s not representation used byDateTime.ToString. It’s using the default format for the current culture – which is apparently one usingdd/MM/yyyy hh:mm:ss tt, effectively.If you need a specific string representation, you can use a standard or custom string format as an argument to
DateTime.ToString, and you can also specify the culture to use. (For example, with a custom string format you may well want to use the invariant culture.)However, if you’re trying to use this as a value – for example in a SQL query – it would be better not to need to convert it into a string to start with. You haven’t told us much about what you’re trying to achieve, but I would try to avoid converting it into a string unless you really have to.