I've got a bit of a two-part question.
Is there a way of changing the format of the value taken from the DatePicker component on Windows Phone 8 toolkit? For example, I'm using SQLite and dates have to be in a certain format so that some SQL can be executed on them (such as aggregate functions). I can insert the value into the database OK, but it's in a format that isn't of real use to me. I've looked around online for a solution, but most only change the StringFormat presented in the DatePicker, not the actual value taken from it.
Here's some ways I've tried to get around this;
DateTime formatStartDate = DateTime.Parse(StartDate);
StartDate = formatStartDate.ToString("yyyy-MM-dd");
DateTime formatEndDate = DateTime.Parse(EndDate);
EndDate = formatEndDate.ToString("yyyy-MM-dd");
Another way I've tried;
StartDate = Convert.ToDateTime(StartDate).ToString("yyyy-MM-dd"),
EndDate = Convert.ToDateTime(EndDate).ToString("yyyy-MM-dd"),
StartDate and EndDate are strings that take the value from the DatePicker. These insert fine and somewhat changes the date, but what it does is rearranges the date format so that it shows up as "yyyy-dd-MM" instead of "yyyy-MM-dd".
Also, the second question that relates to the first, I'm trying to change the value of a bool from true to false (or from 1 to 0 as SQLite doesn't have a bool datatype so I'm using int) in a date column (value taken from the above question) where that date is equal to "now".
The SQL I've tried is (also with just date('now');
string update = @"UPDATE GoalsTrackerModel
SET IsOpen = '0'
WHERE EndDate = datetime('now')";
With EndDate being the column discussed above. I have this code running on start-up so that the value should change as soon as the app is opened if an EndDate has been reached.
What's confusing me about this is that I'm not sure if my SQL for changing IsOpen is correct, but isn't doing what it's supposed to because the date value being stored from the DatePicker is in a wrong format, or if I'm wrong with my WHERE clause and it doesn't matter what format the date is in for this type of query.
Summary; Can you change the value taken from the DatePicker component so that it inserts into a database with the format "yyyy-MM-dd", and how can you check if a date column in the SQLite database equals to today/now?
Thanks for any help.
Aucun commentaire:
Enregistrer un commentaire