Sometimes users play with system date format. How can I check if system date is changed and different then my stored date format.
I found a solution but it seems to me not very good. I compare the year of the system_date and data_date via sysdate.Substring(0,4) and DataDate.Substring(0,4)
But the user can change the date yyyy-dd-MM or to another format.
Is there a more accurate way to do ?
public static bool DateFormatChanged()
{
bool result=true;
string Sys_date = DateTime.Now.ToString("d");
string Data_date="";
using (MySqlConnection conn = new MySqlConnection(PublicVariables.cs))
{
conn.Open();
using (MySqlCommand cmd = new MySqlCommand("SELECT MAX(st_date) as d_date FROM stockdata", conn))
{
MySqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
Data_date = reader["d_date"].ToString();
if(Sysdate.Substring(0,4) != Data_date.Substring(0,4))
result =false;
}
}
}
return result;
}
I think the best way is setting the system format at the begining but I don't know how to do.
Someone has changed the date time to another format I did not pay attention during the backup and the result is above. Accident was waiting this day! When I used the backup of day before and put the format to it's value everything was good except one day lost.