# weekdays, months, quarters & julian Functions in R (4 Examples)

In this article, I’ll explain how to apply the R programming functions **weekdays, months, quarters, and julian**. Let’s have a look at the basic R syntax and the definition of the four functions:

**Basic R Syntax of weekdays, months, quarters & julian:**

weekdays(date) months(date) quarters(date) julian(date, origin = date_origin) |

weekdays(date) months(date) quarters(date) julian(date, origin = date_origin)

**Definition of weekdays, months, quarters & julian:**

The weekdays, months, and quarters functions return the corresponding weekday, month, or quarter of a date object as character string.

The julian function returns the number of days between two date objects as character string.

This tutorial will show you based on **four examples** how to use the weekdays, months, quarters, and julian functions in R.

Let’s dive into it!

## Example 1: weekdays Function in R

In the first example I’ll show you how to find the weekday of a date object in R. Before we can start with the example, we need to create such a date object for the following examples:

date <- as.POSIXlt("2020-05-10") # Create example date date # Print date to RStudio console # "2020-05-10 CEST" |

date <- as.POSIXlt("2020-05-10") # Create example date date # Print date to RStudio console # "2020-05-10 CEST"

As you can see, our date object contains the date *2020-05-10 CEST*.

To this date object, we can now apply the weekdays R function in order to find the corresponding day of the week:

weekdays(date) # Apply weekdays function # "Sunday" |

weekdays(date) # Apply weekdays function # "Sunday"

The weekdays function returns Sunday to the RStudio console. In other words: The 10th of May in the year 2020 is a Sunday.

## Example 2: months Function in R

Similar as before in Example 1, we can apply the months function to extract the month of our date object:

months(date) # Apply months function # "May" |

months(date) # Apply months function # "May"

The date *2020-05-10 CEST* corresponds to the month May (not shocking, I know). Even though the month of a date object might be obvious, the months command can be very useful for a vector containing many date objects.

## Example 3: quarters Function in R

Example 3 shows how to find the quarter of a date object in R. Have a look at the following R code:

quarters(date) # Apply quarters function # "Q2" |

quarters(date) # Apply quarters function # "Q2"

Our example date is in the second quarter (i.e. Q2) of the year.

## Example 4: julian Function in R

The julian function can be used to compute the number of days between two dates. Let’s create a second date object for the next example:

date_origin <- as.POSIXlt("1950-05-10") # Create second date object |

date_origin <- as.POSIXlt("1950-05-10") # Create second date object

Now we can apply the julian R function to calculate the number of days between our two date objects:

julian(date, origin = date_origin) # Apply julian function # Time difference of 25567.96 days |

julian(date, origin = date_origin) # Apply julian function # Time difference of 25567.96 days

The time difference between the 10th of May 1950 and the 10th of May 2020 is 25567.96 days.

## Further Resources for the Handling of Dates in R

Dealing with date objects in R can be quite difficult. For that reason, I have listed some further resources for the handling of dates below. First of all, you might have a look at the R help documentation of the weekdays Function. There you will find further examples and definitions for the weekdays, months, quarters, julian functions. Especially helpful are the following few lines of the help documentation, which define the four functions in further detail:

**Figure 1: R Help Documentation of weekdays, months, quarters & julian.**

Furthermore, you could have a look at the following video of the YouTube channel thenewboston. In the video, the speaker explains how to work with R date objects in general:

Last but not least, you also may have a look at the other R programming tutorials in this website. I have published a few articles on the handling of dates (and many other topics) already:

From this tutorial, you should have learned how to apply weekdays, months, quarters, and julian. However, if you have any further questions, let me know in the comments below.

### Subscribe to my free statistics newsletter:

### R Tutorials

abs Function in R

all & any R Functions

Set Aspect Ratio of Plot

attach & detach R Functions

attr, attributes & structure in R

cbind R Command

Change ggplot2 Legend Title

Character to Numeric in R

Check if Object is Defined

col & row sums, means & medians

Complete Cases in R

Concatenate Vector of Strings

Convert Date to Weekday

cumsum R Function

Data Frame Column to Numeric

diff Command in R

difftime R Function

dim Function in R

dir R Function

Disable Scientific Notation

Draw Segments in R

droplevels R Example

Evaluate an Expression

Extract Characters from String

Factor to Numeric in R

Format Decimal Places

get, get0 & mget in R

is.na R Function

is.null Function in R

jitter R Function

Join Data with dplyr Package

length Function in R

lowess R Smoothing Function

max and min Functions in R

NA Omit in R

nchar R Function

ncol Function in R

nrow Function in R

outer Function in R

pairs & ggpairs Plot

parse, deparse & R expression

paste & paste0 Functions in R

pmax and pmin R Functions

polygon Plots in R

pretty R Function

R Find Missing Values

R Functions List (+ Examples)

R NA – Values

R Replace NA with 0

rbind & rbind.fill in R

Read Excel Files in R

readLines, n.readLines & readline

Remove Element from List

Remove Legend in ggplot2

Rename Column Name in R

Replace Last Comma of String

rev R Command

Round Numeric Data in R

Save & Load RData Workspace

scan R Function

setdiff R Function

setNames vs. setnames in R

sink Command in R

Sort, Order & Rank Data in R

sprintf Function in R

Square Root in R

str_c Function of stringr Package

str_sub Function of stringr Package

strptime & strftime Functions

substr & substring R Commands

sweep R Function

Transform Data Frames

union Function in R

unlist in R

weekdays, months, quarters & julian in R

with & within R Functions

Write Excel File in R