Date Functions Flashcards

1
Q

DATE()

A

DATE(expression)

Returns date

Returns a date given a number, string, or date <expression>.</expression>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

If DATE() does not recognize the input as a date, what should you use instead?

A

DATEPARSE()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

3 functions that changes data from string/integer/date into a date

(doesn’t change the date in any way like truncating or finding the difference)

A

DATE(expression)
DATE(“September 22, 2018”)
DATE(#2018-09-22 14:52#)
Remember: this returns just date and no time

DATEPARSE(date format, date string)
DATEPARSE(‘yyyy-MM-dd’, “2018-09-22”)

MAKEDATE(year, month, day)
MAKEDATE(2018,9,22)
required integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

DATEADD()

A

DATEADD(date_part, interval, date)

Returns date

Returns the <date> with the specified number <interval> added to the specified <date_part> of that date. For example, adding three months or 12 days to a starting date.</date_part></interval></date>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

DATEADD(‘week’, 1, [due date])

A

Push out all due dates by one week

Results in date

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Add 280 days to the date February 20, 2021

A

DATEADD(‘day’, 280, #2/20/21#)

Result: #November 27, 2021#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

DATEDIFF()

A

DATEDIFF(date_part, date1, date2, [start_of_week])

Returns integer

Returns the number of date parts (weeks, years, etc) between two dates in units of <date_part></date_part>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Number of days between March 25, 1986 and February 20, 2021

A

DATEDIFF(‘day’, #3/25/1986#, #2/20/2021#)

Result: 12,751

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Number of days between March 25, 1986 and February 20, 2021 (start of week is Sunday)

A

DATEDIFF(‘day’, #3/25/1986#, #2/20/2021#, ‘sunday’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How many months someone was in a band?

Using [date left band] & [date joined band]

A

DATEDIFF(‘month’, [date joined band], [date left band])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

DATENAME()

A

DATENAME(date_part, date, [start_of_week])

Returns the name of the specified date part as a discrete string.

Bonus: An inverse function is DATEPARSE, which takes a string value and formats it as a date.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

DATENAME(‘year’, #3/25/1986#)

A

Result: “1986”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

DATENAME(‘month’, #1986-03-25#)

A

Result: “March”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

DATEPARSE()

A

DATEPARSE(date_format, date_string)

Returns specifically formatted strings as dates.

The <date_format> argument describes how the <date_string> field is arranged. Because of the variety of ways the string field can be ordered, the <date_format> must match exactly.</date_format></date_string></date_format>

Bonus: Inverse functions, which take dates apart and return the value of their parts, are DATEPART (integer output) and DATENAME (string output).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

DATEPARSE(‘yyyy-MM-dd’, “1986-03-25”)

A

March 25, 1986

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

DATEPART()

A

DATEPART(date_part, date, [start_of_week])

Returns the name of the specified date part as an integer.

Bonus: An inverse function is DATEPARSE, which takes a string value and formats it as a date

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

DATEPART(‘year’, #1986-03-25#)

A

1986

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

DATEPART(‘month’, #1986-03-25#)

A

3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

DATETRUNC()

A

DATETRUNC(date_part, date, [start_of_week])

Think “date rounding”

Output: Date

Changes the date, not the date format (i.e. doesn’t stop showing time)

Truncates the <date> to the accuracy specified by the <date_part>. This function returns a new date. (I.e. when you truncate a date that is in the middle of the month at the month level, this function returns the first day of the month.)</date_part></date>

Bc every date must have a value for day, month, quarter, and year, DATETRUNC sets the values as the lowest value for each date part up to the date part specified.

20
Q

DATETRUNC(‘day’, #5/17/2022 3:12:48 PM#)

A

5/17/2022 12:00:00 AM

21
Q

DATETRUNC(‘day’, #9/22/2018#)

22
Q

DATETRUNC(‘iso-week’, #9/22/2018#)

A

9/17/2018

(the monday of the week containing 9/22/2018)

23
Q

DATETRUNC(quarter, #9/22/2018#)

A

7/1/2018

(the first day of the quarter containing 9/22/2018)

24
Q

DAY()

A

DAY(date)
Returns the day of the month (1-31) as an integer.

25
Day(#September 22, 2018#)
22
26
ISDATE()
ISDATE(string) Checks if the string is a valid date format. Returns true if a given is a valid date. Returns True or False
27
ISDATE(09/22/2018)
True
28
ISDATE(22SEP18)
false
29
ISOQUARTER()
ISOQUARTER(date) Returns Integer Returns the ISO8601 week-based quarter of a given as an integer. ISO = internationally recognized date and calendar format ISO example: September 27, 2022 at 6 p.m. is represented as 2022-09-27 18:00:00.000 (Note that ISOQUARTER would be 3) (In this example, the input is a date value and it doesn't have to be in ISO format. The ISO just will convert it to ISO format and then do the calculation.)
30
MAKEDATE()
MAKEDATE(year, month, day) Returns a date value constructed from the specified , , and . Requires numerical inputs
31
MAKEDATE(1986,3,25)
#1986-03-25#
32
Turn a string date into a date
Try the DATE function. If DATE does not recognize the input try using DATEPARSE.
33
You tried to turn a sting date into an integer date with the DATE function. Issue: DATE does not recognize the input What other function can you use?
try using DATEPARSE
34
MAKEDATETIME()
MAKEDATETIME(date, time) Returns a datetime that combines a and a
35
MAKEDATETIME(#1899-12-30#, #07:59:00#)
**#**12/30/1899 7:59:00 AM**#**
36
MAKETIME()
MAKETIME(hour, minute, second) Returns a date value constructed from the specified , , and . date is 1/1/1899
37
MAKETIME(14, 52, 40)
#1/1/1899 14:52:40# Because Tableau does not support a time data type, only datetime, the output is a datetime. The date portion of the field will be 1/1/1899. BONUS: Similar to MAKEDATETIME
38
MONTH()
Integer Returns the month of the given as an integer.
39
NOW()
Datetime Returns the current local system date and time. NOW() = 1986-03-25 1:08:21 PM
40
date_part
a string constant that tells the function what part of a date to consider, such as day, week, quarter, etc. Examples: 'year' 'dayofyear' (Jan 1) 'minute' 'iso-week'
41
What day starts iso-week? What is the range of outputs?
Monday 1-52
42
What day starts iso-weekday? What is the range of outputs?
Monday 1-7
43
Date format is 'March 25, 1986' What is the data type and result?
String 'March 25, 1986'
44
Date format is #3/25/1986# What is the data type and result?
Date #3/25/1986#
45
Date format is 03/25/1986 What is the data type and result?
Integer 0.0000604230
46
Date format is 1986-03-25 What is the data type and result?
Integer 1,958
47
How can you change the default start of the week to Sunday?
Right click data source > Date properties > Change "Week start:" to Sunday