I have database table in which the dates are stored in the following format
I need to compare the current system date with the date stored in the db. I get the system date using DateTime.Now
But since these 2 dates are in different formatting... how can i convert and compare so that i can select only the required values.
Try this: Get only date from system datetime and compare with database date column value
You also get only date from database
//Database
SELECT CONVERT(date, Transaction_Date) FROM TableName
//Application
if(DateTime.Now.Date==databasedate)
If your database column is datetime format then after pull out data and store in a datetime type variable both will be a C# DateTime instance, So you can compare them without any format specification
DateTime date1 = DateTimeFromDb;
DateTime date2 = DateTime.Now;
int result = DateTime.Compare(date1, date2);
if(result == 0 )
Console.WriteLine("Same")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.