I want to retrieve day of the week from the given date.
For example the date is: 2015-01-28
then it has to return Wednesday
select date_part('week',now()) as weekday;
The above script gives me only number of week but not the day of the week.
To extract the day name from the date, you can use the to_char() function. The first parameter is the date and the second is the desired output format. To extract the full day name, the format should be 'Day' : SELECT to_char( date '2022-01-01' , 'Day' );
Use the DATE_PART() function to retrieve the week number from a date in a PostgreSQL database. This function takes two arguments. The first argument is the date part to retrieve; we use 'week', which returns the week number (e.g. “1” for the first week in January, the first week of the year).
One of the most common issues while migrating from Oracle to Amazon RDS or Amazon Aurora PostgreSQL is with the SYSDATE function. SYSDATE is the most commonly used date/time function in applications or stored procedures and triggers.
Returns a numeric value (1 to 7) representing the day of the week for a specified date or datetime.
Try to_char()
:
select to_char(now(), 'Day')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With