timeperiodsR (version 0.6.2)

this_week: Start and end of week

Description

Defines first and last date in week

Usage

this_week(x = Sys.Date(), 
          part = getOption("timeperiodsR.parts"), 
		      week_start = 1)

Value

Object of tpr class

Arguments

x

Date object

part

Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details.

week_start

Start of week, default = 1 is Monday, 7 is Sunday

Author

Alexey Seleznev

Details

You can get object of tpr class with all components or specify which component you need, use part for manage this option:

  • all - get all components

  • start - get only first date of period

  • end - get only last date of period

  • start - get vector of all dates in period

  • length - get number of dates in period

See Also

For get next other periods see this_quarter(), this_month(), this_year()

Examples

Run this code
## To get start, end and sequence of this weeks
thisweek <- this_week()

## Get this week with start on Sunday
thisweeksun <- this_week(week_start = 7)

## To get vector of date sequences 
this_week(part = "sequence")
this_week()$sequence
seq(thisweek)

## Get number of days of this 2 weeks
day_nums <- this_week(part = "length")
this_week()$length
length(thisweek)

Run the code above in your browser using DataLab