Bonjour
Depuis https://www.sqlite.org/datatype3.htm..._time_datatype
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:
TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.
Autrement dit, tu peux stocker tes dates au format caractère (ISO8601) réel(Date julienne) ou entier(Temps Unix)... Personnellement je préfère ISO.
Dans ce cas, si ta table ressemble à ceci
1 2 3 4
| CREATE TABLE [Commandes] ([Commande_Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
[Date_Reception] DATE NOT NULL,
[Heure_Reception] TIME NOT NULL,
[Prix_Total] NUMERIC NOT NULL) |
tu peux insérer ta commande avec
insert into commandes (date_reception, Heure_Reception, Prix_total) values (date('now'), time('now'), 121.35) (
(la colonne commande_id est automatiquement mise à jour par SQLITE.
Pour les commandes du mois de juin tu pourra faire :
select count(*), sum(prix_total) from commandes where date_reception between '2020-06-01' and '2020-06-30'
(par exemple)
ou
select count(*), sum(prix_total) from commandes where substr(date_reception, 1, 7) = '2020-06'
ou
select count(*), sum(prix_total) from commandes where date_reception like '2020-06%'
Il y a toutes les fonctions nécessaires pour trouver le premier jour d'un mois ou pour ajouter/soustraire des jours à une date. Par exemple le premier jour du mois courant s'obtient par
date('now', 'start of month')
et le dernier jour par
date('now', 'start of month', '1 month', '-1 DAY')
Edit : le 17/06/2020 19:43 pour le dernier jour du mois
Cordialement
Partager