how to convert the DateTime column to date?
I need something like the select * from sales where date = = "2022-09-18";
I need to get all sales from a specific day
I tried this How can I convert datetime to date, truncating the times, leaving me the dates?
and many more solutions but nothing is working.
i tried this SELECT DATE(
datatime) AS date_of_booking FROM sales; " ;
but it gave me this
I tried also this but it gave me error this
this is a table named Sales
if there is anybody that can help me understand how do I get this thing to work please i really appreciate that! a lot .
code for generating the database if you want
DROP DATABASE IF EXISTS ice_cream_store;
CREATE DATABASE IF NOT EXISTS ice_cream_store;
USE ice_cream_store;
CREATE TABLE `Tastes` (
`tid` INTEGER NOT NULL AUTO_INCREMENT primary key,
`name` VARCHAR(20) NOT NULL,
UNIQUE (name)
);
CREATE TABLE `Toppings` (
`topid` INTEGER NOT NULL AUTO_INCREMENT primary key,
`name` VARCHAR(20) NOT NULL,
UNIQUE (name)
);
CREATE TABLE `Receptacles` (
`rid` INTEGER NOT NULL AUTO_INCREMENT primary key,
`name` VARCHAR(20) NOT NULL,
`price` int NOT NULL,
UNIQUE (name)
);
CREATE TABLE `Sales` (
`sid` INTEGER NOT NULL AUTO_INCREMENT primary key,
`rid` integer not null,
foreign key (`rid`) references Receptacles(`rid`),
`datetime` datetime not null,
`completed` bool not null,
`paid` bool not null,
`total_price` INTEGER NOT NULL
);
CREATE TABLE `Tastes_Sales` (
`sid` integer not null,
foreign key (`sid`) references Sales(`sid`),
`tid` integer not null,
foreign key (`tid`) references Tastes(`tid`),
PRIMARY KEY (`sid` , `tid`),
`quantity` integer not null
);
CREATE TABLE `Toppings_Sales` (
`sid` integer not null,
foreign key (`sid`) references Sales(`sid`),
`topid` integer not null,
foreign key (`topid`) references Toppings(`topid`),
PRIMARY KEY (`sid` , `topid`)
);
SELECT
DATE(`datatime`)
AS date_of_booking
FROM sales;
select * from tastes;
select * from Receptacles;
select * from Toppings;
select * from sales;
select * from Toppings_Sales;
select * from Tastes_Sales;
2
Answers
SELECT * from sales WHERE DATE(
datetime
) = '2022-09-15'; this is working for me @RiggsFolly thank you very much!!Use the extract function
Example:
outputs 6
From there you just do:
Now you just add AND operators to do the same for month and year
I think this is a simple enough solution. Hope this works for you.