Data 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
Q

Day(#September 22, 2018#)

26
Q

ISDATE()

A

ISDATE(string)

Checks if the string is a valid date format.

Returns true if a given <string> is a valid date.</string>

Returns True or False

27
Q

ISDATE(09/22/2018)

28
Q

ISDATE(22SEP18)

29
Q

ISOQUARTER()

A

ISOQUARTER(date)

Returns Integer

Returns the ISO8601 week-based quarter of a given <date> as an integer.</date>

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
Q

MAKEDATE()

A

MAKEDATE(year, month, day)

Returns a date value constructed from the specified <year>, <month>, and <day>.</day></month></year>

Requires numerical inputs

31
Q

MAKEDATE(1986,3,25)

A

1986-03-25

32
Q

Turn a string date into a date

A

Try the DATE function.

If DATE does not recognize the input try using DATEPARSE.

33
Q

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?

A

try using DATEPARSE

34
Q

MAKEDATETIME()

A

MAKEDATETIME(date, time)

Returns a datetime that combines a <date> and a <time>.</time></date>

The date can be a date, datetime, or a string type. The time must be a datetime.

BONUS:
Same output as MAKETIME
only available for MYSQL-compatible connections

35
Q

MAKEDATETIME(#1899-12-30#, #07:59:00#)

A

#12/30/1899 7:59:00 AM#

36
Q

MAKETIME()

A

MAKETIME(hour, minute, second)

Returns a date value constructed from the specified <hour>, <minute>, and <second>.</second></minute></hour>

date is 1/1/1899

37
Q

MAKETIME(14, 52, 40)

A

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
Q

MONTH()

A

Integer

Returns the month of the given <date> as an integer.</date>

39
Q

NOW()

A

Datetime

Returns the current local system date and time.

NOW() = 1986-03-25 1:08:21 PM

40
Q

date_part

A

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
Q

What day starts iso-week?
What is the range of outputs?

A

Monday
1-52

42
Q

What day starts iso-weekday?
What is the range of outputs?

A

Monday
1-7

43
Q

Date format is
‘March 25, 1986’

What is the data type and result?

A

String ‘March 25, 1986’

44
Q

Date format is
#3/25/1986#

What is the data type and result?

A

Date #3/25/1986#

45
Q

Date format is
03/25/1986

What is the data type and result?

A

Integer
0.0000604230

46
Q

Date format is
1986-03-25

What is the data type and result?

A

Integer 1,958

47
Q

How can you change the default start of the week to Sunday?

A

Right click data source > Date properties > Change “Week start:” to Sunday