-4

I have DateTime object Edate with value in format of "MM-dd-yyyy" like "01-10-2014" , but i need to use Rowfilter on my Dataview on a Date column which has value in format of "MMM dd,yyyy" like "Jan 10,2014" . I am not able to use Rowfilter because of the format . How can i solve this issue and filter on Date column with format in "MMM dd,yyyy" .

The value is coming from SQLSERVER in which Date column has format of 107 sql datetime format.

Dinesh Kotwani
  • 1
  • 1
  • 1
  • 2
  • 2
    can we get some code? Did you already tried something? – Relax Apr 03 '14 at 07:04
  • See http://stackoverflow.com/questions/3584571/compare-dates-in-dataview-rowfilter - also, use `#yyyy/MM/dd#` for RowFilter, not whatever odd "MMM dd, yyyy" format. Alternatively, just use LINQ instead of RowFilter expressions. (RowFilter is *not* TSQL or SQL Server so the SQL Server / 107 format doesn't matter - see these [RowFilter syntax examples](http://www.csharp-examples.net/dataview-rowfilter/).) – user2864740 Apr 03 '14 at 07:16

3 Answers3

3

Demo for you:

var thisDate1 = DateTime.Now;

Console.WriteLine("Today is " + thisDate1.ToString("MMM dd, yyyy") + ".");

This link you help: Custom Date and Time Format Strings

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Linh Tuan
  • 440
  • 3
  • 11
0

To change the format, you can use toString() method:

Ex:

dateObj.ToString("MMM dd,yyyy");
Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84
gulshanm01
  • 175
  • 6
0

Just like Relax said above; seeing some code would help.

In the meantime, if you are sure the format comes in this format MM-dd-yyyy, you can split it as a string with ('-') to get the individual day, month and year object so you can create a new date instance from the objects with your defined format.

The date function relies on your system culture settings and this determine the expected data format. If you are on Framework 4.5, you can set Global Culture UI in your web.config or app.config for the entire project

Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84
Ammog
  • 124
  • 3