I'm having real issues comparing datetimes in my SQL database. In SQL Server Manager 2014 I'll run something like the following:
SELECT
*
FROM
EmulationSessions
where StaffUser = 'person'
AND Active = 1
AND Created < '2017-02-05 15:38:13'
The row I expect to see looks like this:
But instead I get no result.
Similar attempts to match the format of the database in C# also fail when I convert current time like the following:
System.DateTime currentTime = System.DateTime.Now;
string currentTimeString = System.DateTime
.Parse(currentTime.ToString(), new CultureInfo("en-AU"))
.ToString("yyyy-MM-dd hh24:mm:ss");
Is there another conversion step I'm missing?
SQL Server defualt format is 'YYYY-MM-DD', In your case '02' is considered as month. Check like this,
SELECT
*
FROM
EmulationSessions
where StaffUser = 'person'
AND Active = 1
AND Created < '2017-05-02 15:38:13'