I have the following problem. The timeformat my database gives me back depends on the server settings. So, if I do this query:
string query = "SELECT d.id, i.name, d.address, d.sensor, d.value, d.made, d.received, s.type, r.name AS room
FROM info AS i
RIGHT JOIN data AS d ON i.address = d.address AND i.sensor = d.sensor
LEFT JOIN sensor_types AS s ON i.type = s.id
LEFT JOIN room AS r ON i.room = r.id
WHERE i.address = '" + address + "'
&& i.sensor = '" + sensor + "'
&& DATE(d.received) BETWEEN '" + start + "' AND '" + end + "'";
On server 1 I get back for today 2013-12-23 2:29:14 and on server 2 I get back 23-12-2013 2:29:14.
In some cases I need the unixtime so I use this function for it, which works fine in case 1 but gives an error in case 2:
public string DateTimeToUnixTime(string text)
{
DateTime myDate = DateTime.ParseExact(text, "yyyy-MM-dd HH:mm:ss",
System.Globalization.CultureInfo.InvariantCulture);
TimeSpan span = (myDate - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime());
//return the total seconds (which is a UNIX timestamp)
return ((double)span.TotalSeconds).ToString();
}
What is the best way to fix this?