Query to Determine First Day of the Week

Moderator: NorbertKrupa

Post Reply
sarah
Intermediate
Intermediate
Posts: 77
Joined: Mon Aug 27, 2012 1:34 pm

Query to Determine First Day of the Week

Post by sarah » Thu Mar 21, 2013 12:55 pm

Hello,

Can someone help me figure out a very fast query that can determine the date of the first day of the week (assuming Monday is the first day) for a given date?

For instance, for today, 03/21/2013 I would like to get Monday, 03/18/2013, as a result.

Thanks!
Have a GREAT day!

User avatar
Julie
Master
Master
Posts: 221
Joined: Thu Apr 19, 2012 9:29 pm

Re: Query to Determine First Day of the Week

Post by Julie » Thu Mar 21, 2013 12:59 pm

Sarah,

You are in luck! Vertica has a function to do that:

Code: Select all

dbadmin=> SELECT date_trunc('week', DATE '03/21/2013');
     date_trunc
---------------------
 2013-03-18 00:00:00
(1 row)
Refer to the post viewtopic.php?f=63&t=375&p=1189&hilit=date_trunc#p1189 for more examples that use the date_trunc function.
Thanks,
Juliette

sarah
Intermediate
Intermediate
Posts: 77
Joined: Mon Aug 27, 2012 1:34 pm

Re: Query to Determine First Day of the Week

Post by sarah » Thu Mar 21, 2013 1:29 pm

Thanks, Julie! That's perfect!
Have a GREAT day!

Post Reply

Return to “Vertica SQL”