In SQL, you can use the GETDATE()
or CURRENT_TIMESTAMP
function to retrieve the current date and time. If you only want the current date, you can use the CAST
or CONVERT
functions to extract the date part. Here are a couple of examples:
- Using
GETDATE()
:
SELECT GETDATE() AS CurrentDateAndTime;
- Using
CURRENT_TIMESTAMP
:
SELECT CURRENT_TIMESTAMP AS CurrentDateAndTime;
- Extracting only the date using
CAST
or CONVERT
:
SELECT CAST(GETDATE() AS DATE) AS CurrentDate;
SELECT CONVERT(DATE, GETDATE()) AS CurrentDate;
Any of these queries should give you the current date or date and time, depending on your specific requirements.