mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 23:28:02 +00:00
Add Day Of Week For A Date as a postgres til
This commit is contained in:
@@ -136,6 +136,7 @@ _310 TILs and counting..._
|
||||
- [Create A Composite Primary Key](postgres/create-a-composite-primary-key.md)
|
||||
- [Create hstore From Two Arrays](postgres/create-hstore-from-two-arrays.md)
|
||||
- [Creating Conditional Constraints](postgres/creating-conditional-constraints.md)
|
||||
- [Day Of Week For A Date](postgres/day-of-week-for-a-date.md)
|
||||
- [Default Schema](postgres/default-schema.md)
|
||||
- [Defining Arrays](postgres/defining-arrays.md)
|
||||
- [Edit Existing Functions](postgres/edit-existing-functions.md)
|
||||
|
||||
22
postgres/day-of-week-for-a-date.md
Normal file
22
postgres/day-of-week-for-a-date.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# Day Of Week For A Date
|
||||
|
||||
Given a `date` in PostgreSQL
|
||||
|
||||
```sql
|
||||
> select '2050-1-1'::date;
|
||||
date
|
||||
------------
|
||||
2050-01-01
|
||||
```
|
||||
|
||||
you can determine the day of the week for that date with the `date_part()`
|
||||
function
|
||||
|
||||
```sql
|
||||
> select date_part('dow', '2050-1-1'::date);
|
||||
date_part
|
||||
-----------
|
||||
6
|
||||
```
|
||||
|
||||
[source](http://www.postgresql.org/docs/current/static/functions-datetime.html)
|
||||
Reference in New Issue
Block a user