﻿1
00:00:00,000 --> 00:00:05,580
<font color="#E5E5E5">this is part 125 of sequel server</font>

2
00:00:02,190 --> 00:00:08,099
<font color="#CCCCCC">tutorial in this</font><font color="#E5E5E5"> video well discuss</font><font color="#CCCCCC"> evo</font>

3
00:00:05,580 --> 00:00:10,800
month function in sequel server<font color="#CCCCCC"> Evo</font>

4
00:00:08,099 --> 00:00:12,900
stands for<font color="#CCCCCC"> and off so this</font><font color="#E5E5E5"> is end of</font>

5
00:00:10,800 --> 00:00:15,450
month function<font color="#E5E5E5"> it's introduced in</font>

6
00:00:12,900 --> 00:00:17,430
sequence<font color="#CCCCCC"> over 2012 it returns the last</font>

7
00:00:15,450 --> 00:00:19,590
day of the month of the specified date

8
00:00:17,430 --> 00:00:21,448
<font color="#E5E5E5">here is the syntax the first parameter</font>

9
00:00:19,590 --> 00:00:23,640
for<font color="#E5E5E5"> this function is the start date</font><font color="#CCCCCC"> so</font>

10
00:00:21,449 --> 00:00:25,949
<font color="#CCCCCC">that is the date for which to return</font><font color="#E5E5E5"> the</font>

11
00:00:23,640 --> 00:00:27,960
last day of the<font color="#CCCCCC"> month</font><font color="#E5E5E5"> the second</font>

12
00:00:25,949 --> 00:00:30,539
parameter is month to<font color="#CCCCCC"> add this is</font>

13
00:00:27,960 --> 00:00:32,820
optional<font color="#E5E5E5"> this parameter specifies the</font>

14
00:00:30,539 --> 00:00:35,370
number<font color="#E5E5E5"> of months to add to the start</font>

15
00:00:32,820 --> 00:00:37,500
<font color="#CCCCCC">date so</font><font color="#E5E5E5"> if we specify a value for the</font>

16
00:00:35,370 --> 00:00:39,269
second<font color="#E5E5E5"> optional parameter then end of</font>

17
00:00:37,500 --> 00:00:41,820
month is going to<font color="#E5E5E5"> add those number of</font>

18
00:00:39,270 --> 00:00:44,219
<font color="#E5E5E5">months to</font><font color="#CCCCCC"> the start date and then it is</font>

19
00:00:41,820 --> 00:00:46,530
<font color="#E5E5E5">going to return the last day from the</font>

20
00:00:44,219 --> 00:00:49,200
resulting date<font color="#E5E5E5"> let's look at an example</font>

21
00:00:46,530 --> 00:00:51,899
<font color="#CCCCCC">now</font><font color="#E5E5E5"> so notice here we</font><font color="#CCCCCC"> are</font><font color="#E5E5E5"> passing this</font>

22
00:00:49,200 --> 00:00:53,039
state<font color="#E5E5E5"> to end of month function and if</font>

23
00:00:51,899 --> 00:00:56,610
you look at the month here it is

24
00:00:53,039 --> 00:00:59,760
<font color="#CCCCCC">November</font><font color="#E5E5E5"> and November month has got 30</font>

25
00:00:56,610 --> 00:01:04,289
days so the last<font color="#E5E5E5"> day of November</font><font color="#CCCCCC"> 20th</font>

26
00:00:59,760 --> 00:01:06,298
2015<font color="#E5E5E5"> should be 30th of November 2015</font><font color="#CCCCCC"> I</font>

27
00:01:04,290 --> 00:01:08,670
have the same query already typed here

28
00:01:06,299 --> 00:01:13,380
<font color="#E5E5E5">so when we execute this we should get</font>

29
00:01:08,670 --> 00:01:16,140
30th of November<font color="#E5E5E5"> as the last day now</font>

30
00:01:13,380 --> 00:01:18,390
<font color="#E5E5E5">let's look at an</font><font color="#CCCCCC"> example of retrieving</font>

31
00:01:16,140 --> 00:01:22,229
the last day from the<font color="#CCCCCC"> February month</font>

32
00:01:18,390 --> 00:01:25,080
<font color="#E5E5E5">from a non-leap year 2015 is a non-leap</font>

33
00:01:22,229 --> 00:01:27,390
year<font color="#E5E5E5"> and we want the last day of</font>

34
00:01:25,080 --> 00:01:30,600
February month<font color="#E5E5E5"> so I'm going to specify</font>

35
00:01:27,390 --> 00:01:33,960
<font color="#E5E5E5">the month number</font><font color="#CCCCCC"> as 2 in a non-leap year</font>

36
00:01:30,600 --> 00:01:36,149
<font color="#E5E5E5">February has 28 days so when we execute</font>

37
00:01:33,960 --> 00:01:39,750
this query we should get 20th of

38
00:01:36,150 --> 00:01:42,450
<font color="#E5E5E5">February as the last day notice that we</font>

39
00:01:39,750 --> 00:01:44,610
get 28th<font color="#CCCCCC"> of February as the last day now</font>

40
00:01:42,450 --> 00:01:48,540
let's look at doing<font color="#E5E5E5"> the same thing from</font>

41
00:01:44,610 --> 00:01:50,970
<font color="#CCCCCC">alipio 2016 is alipio now how do</font><font color="#E5E5E5"> we know</font>

42
00:01:48,540 --> 00:01:54,270
a specific<font color="#E5E5E5"> year is in leap year if that</font>

43
00:01:50,970 --> 00:01:57,960
year is divisible by 4 then<font color="#CCCCCC"> we know it's</font>

44
00:01:54,270 --> 00:02:01,320
a leap year<font color="#E5E5E5"> so 2016 is divisible by 4</font><font color="#CCCCCC"> so</font>

45
00:01:57,960 --> 00:02:04,770
<font color="#CCCCCC">we get 504 so that's alipio</font><font color="#E5E5E5"> with an</font>

46
00:02:01,320 --> 00:02:07,589
<font color="#CCCCCC">olympia february has got 29 days so when</font>

47
00:02:04,770 --> 00:02:11,790
we<font color="#E5E5E5"> execute the same query we should get</font>

48
00:02:07,590 --> 00:02:12,970
29th of<font color="#CCCCCC"> february</font><font color="#E5E5E5"> as the last day notice</font>

49
00:02:11,790 --> 00:02:15,489
<font color="#E5E5E5">29th of</font>

50
00:02:12,970 --> 00:02:17,410
ready now let's<font color="#CCCCCC"> look</font><font color="#E5E5E5"> at an example of</font>

51
00:02:15,490 --> 00:02:20,470
using<font color="#E5E5E5"> the second optional parameter</font>

52
00:02:17,410 --> 00:02:22,840
<font color="#E5E5E5">month to add when we specify a value for</font>

53
00:02:20,470 --> 00:02:25,330
this<font color="#CCCCCC"> parameter</font><font color="#E5E5E5"> it's going to add those</font>

54
00:02:22,840 --> 00:02:28,270
many number<font color="#CCCCCC"> of months to</font><font color="#E5E5E5"> the start date</font>

55
00:02:25,330 --> 00:02:29,770
<font color="#CCCCCC">and from the resulting date</font><font color="#E5E5E5"> the end of</font>

56
00:02:28,270 --> 00:02:31,960
month<font color="#CCCCCC"> is</font><font color="#E5E5E5"> going to return</font><font color="#CCCCCC"> us the last</font>

57
00:02:29,770 --> 00:02:37,000
<font color="#CCCCCC">eight so the moment the day that we have</font>

58
00:02:31,960 --> 00:02:40,270
is February<font color="#E5E5E5"> 28 2016 now what I'm going</font>

59
00:02:37,000 --> 00:02:42,640
<font color="#CCCCCC">to do is add two months to it</font><font color="#E5E5E5"> so when we</font>

60
00:02:40,270 --> 00:02:46,120
add two months to February we will get

61
00:02:42,640 --> 00:02:51,369
April March and April<font color="#CCCCCC"> okay so we want to</font>

62
00:02:46,120 --> 00:02:54,790
find the last day of April<font color="#E5E5E5"> 2016 so let's</font>

63
00:02:51,370 --> 00:02:58,890
execute this in April<font color="#CCCCCC"> we've got 30 days</font>

64
00:02:54,790 --> 00:03:01,120
<font color="#E5E5E5">look at that April 30th is the last day</font>

65
00:02:58,890 --> 00:03:03,880
now let's look at an<font color="#CCCCCC"> example of</font>

66
00:03:01,120 --> 00:03:06,160
subtracting<font color="#CCCCCC"> a month you know from the</font>

67
00:03:03,880 --> 00:03:08,350
start<font color="#E5E5E5"> date to subtract a month all you</font>

68
00:03:06,160 --> 00:03:11,320
have<font color="#E5E5E5"> to do is use a negative number</font>

69
00:03:08,350 --> 00:03:13,720
<font color="#E5E5E5">let's say I want to subtract one month</font>

70
00:03:11,320 --> 00:03:15,730
and then compute<font color="#CCCCCC"> the end of that</font>

71
00:03:13,720 --> 00:03:17,680
resulting date so in this case it's

72
00:03:15,730 --> 00:03:20,018
going to subtract<font color="#E5E5E5"> one month so when we</font>

73
00:03:17,680 --> 00:03:22,930
subtract one from February we are going

74
00:03:20,019 --> 00:03:25,180
to get you know January 2016<font color="#CCCCCC"> in the</font>

75
00:03:22,930 --> 00:03:29,560
<font color="#CCCCCC">month of January we have caught 31 days</font>

76
00:03:25,180 --> 00:03:33,580
<font color="#E5E5E5">so January 31st 2016 should be the last</font>

77
00:03:29,560 --> 00:03:36,070
<font color="#E5E5E5">day we have all those examples right</font>

78
00:03:33,580 --> 00:03:38,620
<font color="#CCCCCC">here now let's look at an example of</font>

79
00:03:36,070 --> 00:03:41,709
using<font color="#E5E5E5"> this end of month function with</font>

80
00:03:38,620 --> 00:03:44,110
table data<font color="#CCCCCC"> we'll use this</font><font color="#E5E5E5"> employees</font>

81
00:03:41,709 --> 00:03:45,940
table for this<font color="#E5E5E5"> example notice</font><font color="#CCCCCC"> that we've</font>

82
00:03:44,110 --> 00:03:48,580
got<font color="#CCCCCC"> three columns</font><font color="#E5E5E5"> in this table ID name</font>

83
00:03:45,940 --> 00:03:52,450
<font color="#E5E5E5">and date of birth what we want to do is</font>

84
00:03:48,580 --> 00:03:54,790
return<font color="#E5E5E5"> the last day of the month</font><font color="#CCCCCC"> from</font>

85
00:03:52,450 --> 00:03:57,329
<font color="#E5E5E5">the date of birth of every employee so</font>

86
00:03:54,790 --> 00:04:02,200
if you look at mark<font color="#CCCCCC"> is born on you know</font>

87
00:03:57,330 --> 00:04:05,080
<font color="#CCCCCC">January 11th</font><font color="#E5E5E5"> 1980 Don is born on 12th of</font>

88
00:04:02,200 --> 00:04:08,109
December 1981<font color="#CCCCCC"> so from their date of</font>

89
00:04:05,080 --> 00:04:12,280
<font color="#CCCCCC">births we want the</font><font color="#E5E5E5"> last day of the month</font>

90
00:04:08,110 --> 00:04:15,610
so for January<font color="#E5E5E5"> it is 31st of January for</font>

91
00:04:12,280 --> 00:04:18,459
December this 31st of December<font color="#E5E5E5"> for</font>

92
00:04:15,610 --> 00:04:20,890
November<font color="#E5E5E5"> it is 30th of November</font><font color="#CCCCCC"> so from</font>

93
00:04:18,459 --> 00:04:21,690
the date of<font color="#E5E5E5"> birth of every</font><font color="#CCCCCC"> employee</font><font color="#E5E5E5"> we</font>

94
00:04:20,890 --> 00:04:24,900
want the

95
00:04:21,690 --> 00:04:27,980
last day<font color="#CCCCCC"> of that month okay</font><font color="#E5E5E5"> so let's</font>

96
00:04:24,900 --> 00:04:31,650
look at an<font color="#CCCCCC"> example</font><font color="#E5E5E5"> of</font><font color="#CCCCCC"> using that</font>

97
00:04:27,980 --> 00:04:35,190
<font color="#CCCCCC">end-of-month</font><font color="#E5E5E5"> function with table data so</font>

98
00:04:31,650 --> 00:04:39,359
I'm going<font color="#E5E5E5"> to use end of month and we</font>

99
00:04:35,190 --> 00:04:41,610
want to use it on<font color="#CCCCCC"> date of birth</font><font color="#E5E5E5"> column</font>

100
00:04:39,360 --> 00:04:48,420
and what I'm going to do is retrieve<font color="#E5E5E5"> the</font>

101
00:04:41,610 --> 00:04:51,510
date of birth column as well and let's

102
00:04:48,420 --> 00:04:55,740
give this column the last column<font color="#CCCCCC"> and</font>

103
00:04:51,510 --> 00:04:58,110
<font color="#CCCCCC">aleeah's let's call this last day so</font>

104
00:04:55,740 --> 00:05:00,900
when we execute<font color="#E5E5E5"> this we should get the</font>

105
00:04:58,110 --> 00:05:03,630
last day<font color="#E5E5E5"> from the date of birth of every</font>

106
00:05:00,900 --> 00:05:05,219
<font color="#E5E5E5">employee</font><font color="#CCCCCC"> okay</font><font color="#E5E5E5"> so at the moment we are</font>

107
00:05:03,630 --> 00:05:07,740
getting the complete<font color="#E5E5E5"> date</font>

108
00:05:05,220 --> 00:05:10,800
now instead of complete date if you want

109
00:05:07,740 --> 00:05:13,230
just<font color="#E5E5E5"> the last day as you can</font><font color="#CCCCCC"> see here</font>

110
00:05:10,800 --> 00:05:16,290
from<font color="#E5E5E5"> the month of their date of birth</font>

111
00:05:13,230 --> 00:05:19,350
<font color="#E5E5E5">then use date part function so all you</font>

112
00:05:16,290 --> 00:05:21,270
<font color="#E5E5E5">need to do here is so this end of month</font>

113
00:05:19,350 --> 00:05:23,970
is<font color="#CCCCCC"> actually going to</font><font color="#E5E5E5"> return a date</font><font color="#CCCCCC"> so</font>

114
00:05:21,270 --> 00:05:25,950
from<font color="#E5E5E5"> that date I want a part of it so</font>

115
00:05:23,970 --> 00:05:29,160
I'm going<font color="#CCCCCC"> to</font><font color="#E5E5E5"> use date part function all</font>

116
00:05:25,950 --> 00:05:34,140
I want is the date<font color="#E5E5E5"> part okay I don't</font>

117
00:05:29,160 --> 00:05:36,480
want<font color="#E5E5E5"> month and</font><font color="#CCCCCC"> year so we want date part</font>

118
00:05:34,140 --> 00:05:38,729
when we<font color="#E5E5E5"> execute this we should get</font><font color="#CCCCCC"> only</font>

119
00:05:36,480 --> 00:05:42,110
the last day of the month not the

120
00:05:38,730 --> 00:05:44,160
complete<font color="#E5E5E5"> data as</font><font color="#CCCCCC"> you can see it here</font>

121
00:05:42,110 --> 00:05:46,610
thank you<font color="#E5E5E5"> for listening</font><font color="#CCCCCC"> and have a great</font>

122
00:05:44,160 --> 00:05:46,610
<font color="#E5E5E5">day</font>


