Using CURRENT_DATE, CURRENT_TIMESTAMP, and NOW() in PostgreSQL
📖 Scenario: You are managing a simple event log table in a PostgreSQL database. You want to record the date and time when each event is added.
🎯 Goal: Create a table to store event names and their timestamps. Then insert a new event using CURRENT_DATE, CURRENT_TIMESTAMP, and NOW() to record the date and time of the event.
📋 What You'll Learn
Create a table called
event_log with columns event_name (text), event_date (date), and event_time (timestamp).Insert a new event named
'UserLogin' using CURRENT_DATE for the date and CURRENT_TIMESTAMP for the timestamp.Insert another event named
'PageView' using NOW() for the timestamp and CURRENT_DATE for the date.Select all rows from
event_log to see the stored events with their dates and times.💡 Why This Matters
🌍 Real World
Recording event times is common in logging user actions, transactions, or system events in databases.
💼 Career
Understanding how to use date and time functions in SQL is essential for database administrators and backend developers to track and analyze data changes over time.
Progress0 / 4 steps