mirror of
https://github.com/jbranchaud/til
synced 2026-01-18 06:28:02 +00:00
Add Day Of Week By Name For A Date as a postgres til
This commit is contained in:
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
|
|||||||
warrant a full blog post. These are mostly things I learn by pairing with
|
warrant a full blog post. These are mostly things I learn by pairing with
|
||||||
smart people at [Hashrocket](http://hashrocket.com/).
|
smart people at [Hashrocket](http://hashrocket.com/).
|
||||||
|
|
||||||
_316 TILs and counting..._
|
_317 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -137,6 +137,7 @@ _316 TILs and counting..._
|
|||||||
- [Create A Composite Primary Key](postgres/create-a-composite-primary-key.md)
|
- [Create A Composite Primary Key](postgres/create-a-composite-primary-key.md)
|
||||||
- [Create hstore From Two Arrays](postgres/create-hstore-from-two-arrays.md)
|
- [Create hstore From Two Arrays](postgres/create-hstore-from-two-arrays.md)
|
||||||
- [Creating Conditional Constraints](postgres/creating-conditional-constraints.md)
|
- [Creating Conditional Constraints](postgres/creating-conditional-constraints.md)
|
||||||
|
- [Day Of Week By Name For A Date](postgres/day-of-week-by-name-for-a-date.md)
|
||||||
- [Day Of Week For A Date](postgres/day-of-week-for-a-date.md)
|
- [Day Of Week For A Date](postgres/day-of-week-for-a-date.md)
|
||||||
- [Default Schema](postgres/default-schema.md)
|
- [Default Schema](postgres/default-schema.md)
|
||||||
- [Defining Arrays](postgres/defining-arrays.md)
|
- [Defining Arrays](postgres/defining-arrays.md)
|
||||||
|
|||||||
22
postgres/day-of-week-by-name-for-a-date.md
Normal file
22
postgres/day-of-week-by-name-for-a-date.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Day Of Week By Name For A Date
|
||||||
|
|
||||||
|
In [Day Of Week For A Date](day-of-week-for-a-date.md), I explained how to
|
||||||
|
determine what day of the week a date is as an integer with PostgreSQL. This
|
||||||
|
used the `date_part()` function. By using the `to_char()` function with a
|
||||||
|
date or timestamp, we can determine the day of the week by name (e.g.
|
||||||
|
Monday). For instance, to determine what day today is, try a statement like
|
||||||
|
the following:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
> select to_char(now(), 'Day');
|
||||||
|
to_char
|
||||||
|
-----------
|
||||||
|
Sunday
|
||||||
|
```
|
||||||
|
|
||||||
|
The `Day` part of the second argument is just one of many template patterns
|
||||||
|
that can be used for formatting dates and times.
|
||||||
|
|
||||||
|
See [Data Type Formatting
|
||||||
|
Functions](http://www.postgresql.org/docs/current/static/functions-formatting.html)
|
||||||
|
in the Postgres docs for more details.
|
||||||
Reference in New Issue
Block a user