In sqllite I have date and I have a query :
INSERT INTO stats_project_funds(id_project, id_funds, month,stake, stake_in_units, stake_in_percent, profit, profit_in_units, picks, hitrate, won, draw, lost)
VALUES(1, 5, strftime("%Y-%m",'27.12.2011'), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
As you can see date is in Russian format. My program is written in European localization where date format is 27-12-2011. What I have to change that this query will be for all localizations ? Now this field in the database is datatime type. Better solution will be change it to varchar and insert string value ? In field only year and month is stored.
My query looks like this:
DateTime newMonth = DateTime.Parse(month);
StringBuilder query = new StringBuilder();
query.AppendFormat(" INSERT INTO stats_project_funds(id_project, id_funds, month,stake, stake_in_units, "
+ " stake_in_percent, profit, profit_in_units, picks, hitrate, won, draw, lost) "
+ " VALUES({0}, {1}, strftime(\"%Y-%m\",'{2}'), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); ", idProject, idFunds, newMonth.Date.ToShortDateString());
return query.ToString();
Thanks
I would use parameters instead String Builder, it is much cleaner, safer and less error prone. This way, you don’t have to worry about date formats and this is the preferred way of working with parameters.