0
0
MySQLquery~30 mins

NOW, CURDATE, CURTIME in MySQL - Mini Project: Build & Apply

Choose your learning style9 modes available
Using NOW, CURDATE, and CURTIME in MySQL
📖 Scenario: You are managing a small online store database. You want to keep track of when orders are placed by storing the full date and time, just the date, and just the time separately for analysis.
🎯 Goal: Build a simple MySQL table to store order timestamps using the NOW(), CURDATE(), and CURTIME() functions.
📋 What You'll Learn
Create a table called orders with columns order_id, order_datetime, order_date, and order_time.
Insert one row into orders using NOW() for order_datetime, CURDATE() for order_date, and CURTIME() for order_time.
Select all columns from the orders table to see the stored timestamps.
💡 Why This Matters
🌍 Real World
Tracking order times helps businesses analyze sales patterns and improve customer service.
💼 Career
Database developers and analysts often use date and time functions to manage and report on time-sensitive data.
Progress0 / 4 steps
1
Create the orders table
Write a SQL statement to create a table called orders with these columns: order_id as an integer primary key, order_datetime as DATETIME, order_date as DATE, and order_time as TIME.
MySQL
Need a hint?

Use CREATE TABLE orders and define each column with its type. Remember to set order_id as the primary key.

2
Insert a row using NOW(), CURDATE(), and CURTIME()
Write a SQL INSERT statement to add one row into orders with order_id 1, order_datetime set to NOW(), order_date set to CURDATE(), and order_time set to CURTIME().
MySQL
Need a hint?

Use INSERT INTO orders (order_id, order_datetime, order_date, order_time) and set the values using the MySQL functions NOW(), CURDATE(), and CURTIME().

3
Select all data from orders
Write a SQL SELECT statement to get all columns and rows from the orders table.
MySQL
Need a hint?

Use SELECT * FROM orders; to see all the data you inserted.

4
Add a new order with NOW(), CURDATE(), and CURTIME()
Write a SQL INSERT statement to add a second row into orders with order_id 2, using NOW() for order_datetime, CURDATE() for order_date, and CURTIME() for order_time.
MySQL
Need a hint?

Use the same pattern as before but change order_id to 2.