1 00:00:00,700 --> 00:00:05,278 We've seen how we can use variables with PHP to make updates faster. 2 00:00:05,278 --> 00:00:08,706 Now let's get PHP to make some actual updates for us. 3 00:00:08,706 --> 00:00:13,278 PHP has many built in functions that can be used to handle complex programming 4 00:00:13,278 --> 00:00:13,780 tasks. 5 00:00:15,010 --> 00:00:19,210 How long after the New Year do you keep writing the previous year for dates? 6 00:00:19,210 --> 00:00:22,700 I'm usually good in January but then start slipping again in February. 7 00:00:22,700 --> 00:00:26,300 And who wants to spend their first week of the New Year updating copyright dates 8 00:00:26,300 --> 00:00:28,680 in every footer on every web page? 9 00:00:28,680 --> 00:00:31,280 Instead, let PHP do it for you. 10 00:00:31,280 --> 00:00:35,410 We'll be using the date function that we used in the daily exercise program. 11 00:00:35,410 --> 00:00:39,030 I've included a link to the documentation in the teacher's notes. 12 00:00:39,030 --> 00:00:41,670 You've already added code blocks to this page, so 13 00:00:41,670 --> 00:00:43,115 you have all the tools that you need. 14 00:00:43,115 --> 00:00:46,480 Pause this video and see if you can change the year 15 00:00:46,480 --> 00:00:50,120 in the footer to have PHP automatically update that for us. 16 00:00:51,410 --> 00:00:52,720 Go ahead I'll wait right here. 17 00:00:53,870 --> 00:00:55,760 So, did you figure it out? 18 00:00:55,760 --> 00:00:58,220 Don't worry if you didn't quite get there this time, 19 00:00:58,220 --> 00:00:59,970 I'll take you through each step right now. 20 00:01:01,780 --> 00:01:03,337 Down here in the footer, 21 00:01:03,337 --> 00:01:07,353 we want to replace the year 2016 with the PHP date function. 22 00:01:07,353 --> 00:01:10,254 To start, we replace the year with the PHP code block. 23 00:01:15,410 --> 00:01:17,280 The next step is to add our function call. 24 00:01:20,420 --> 00:01:24,330 This time we want the date function to return the four digit year, so 25 00:01:24,330 --> 00:01:28,200 we pass the capital Y in quotes to the date function. 26 00:01:28,200 --> 00:01:32,080 Check the teacher's notes for a link to the docs with all the options available. 27 00:01:32,080 --> 00:01:35,990 For controlling how the date function outputs date information. 28 00:01:35,990 --> 00:01:37,920 Let's save the file and refresh the browser. 29 00:01:39,710 --> 00:01:43,520 Now the year is gone completely but there's no errors, so what went wrong. 30 00:01:43,520 --> 00:01:44,700 Let's go back to work spaces. 31 00:01:45,870 --> 00:01:49,920 The call to the function is good but it only returns the value, 32 00:01:49,920 --> 00:01:53,620 we haven't told the script what we want to do with the value. 33 00:01:53,620 --> 00:01:58,500 For our daily exercise program we assign the value to a variable called Today. 34 00:01:58,500 --> 00:02:01,460 This time we just want to display the value, 35 00:02:01,460 --> 00:02:04,663 so let's add the echo command before the date. 36 00:02:04,663 --> 00:02:09,000 Now we can save and refresh our browser again. 37 00:02:09,000 --> 00:02:10,970 Great, this time we see the current year. 38 00:02:13,360 --> 00:02:17,460 Awesome, now we don't have to worry about updating that date for the new year. 39 00:02:17,460 --> 00:02:21,310 But PHP provides even more built in functions that we can use, 40 00:02:21,310 --> 00:02:25,070 sometimes the page may also contain our last modified date. 41 00:02:25,070 --> 00:02:26,160 This can be helpful for 42 00:02:26,160 --> 00:02:30,440 information that is time sensitive such as news or a report. 43 00:02:30,440 --> 00:02:34,160 But I don't wanna have to rely on my memory to update that last modified date, 44 00:02:34,160 --> 00:02:36,585 we could be in trouble if we did. 45 00:02:36,585 --> 00:02:40,960 PHP to the rescue, let's pull up the docs for the date function. 46 00:02:42,630 --> 00:02:43,220 In the docs for 47 00:02:43,220 --> 00:02:48,100 the date function, we can see that we can pass a second optional parameter as well. 48 00:02:48,100 --> 00:02:52,346 By default it uses the current timestamp this moment in time. 49 00:02:52,346 --> 00:02:57,382 But we can also specify a timestamp if we want to use a different date or time. 50 00:02:57,382 --> 00:03:00,948 There are many different ways to use PHP to create a timestamp, 51 00:03:00,948 --> 00:03:03,450 let's scroll down to the see also heading. 52 00:03:05,600 --> 00:03:09,870 For this solution, I want to get the timestamp of the last modified date 53 00:03:09,870 --> 00:03:14,475 to do that we use a function call getlastmod. 54 00:03:14,475 --> 00:03:19,360 Getlastmod, gets the time of the last modification of the current page. 55 00:03:19,360 --> 00:03:21,520 Since a function returns a value, 56 00:03:21,520 --> 00:03:25,800 I can use a function within another function to supply a value. 57 00:03:25,800 --> 00:03:29,508 If you scroll down you can see the first example on the getlastmod page. 58 00:03:31,430 --> 00:03:34,495 Let's copy this code block and use it in our footer as well. 59 00:03:39,100 --> 00:03:42,920 We can also combine these code blocks, so that it's all one code block. 60 00:03:42,920 --> 00:03:47,481 Combining code blocks when there's no HTML separating them can once again make things 61 00:03:47,481 --> 00:03:48,358 easier to read. 62 00:03:56,750 --> 00:03:59,201 Now let's save this page and refresh our browser. 63 00:04:01,580 --> 00:04:06,050 So, now we see last modified with a month, day, year and time. 64 00:04:06,050 --> 00:04:07,590 When we refresh the page, 65 00:04:07,590 --> 00:04:11,470 the last modified date doesn't change because we have not resaved the file. 66 00:04:12,630 --> 00:04:16,090 We should put some space separating the name and the last word. 67 00:04:16,090 --> 00:04:19,260 So let's modify the file again and add a period and a space. 68 00:04:21,820 --> 00:04:23,508 Let's add some things here. 69 00:04:23,508 --> 00:04:27,620 We wanna space after the year and 70 00:04:27,620 --> 00:04:33,290 we'll add a period and a space at the end. 71 00:04:34,870 --> 00:04:39,020 This time when we refresh the browser, we see a period and a space. 72 00:04:39,020 --> 00:04:43,440 We also see that the time did change because we made changes to the file. 73 00:04:44,940 --> 00:04:49,941 Nice work, you're learning to make use of one of the programmers' greatest strengths, 74 00:04:49,941 --> 00:04:51,080 laziness. 75 00:04:51,080 --> 00:04:54,736 According to Larry Wall author of the Perl Programming Language, 76 00:04:54,736 --> 00:04:57,820 laziness is one of the greatest virtues of a programmer. 77 00:04:57,820 --> 00:05:03,020 Because it makes you go through great efforts to reduce how much energy you use. 78 00:05:03,020 --> 00:05:07,880 Laziness makes you write labor saving programs that other people find useful. 79 00:05:07,880 --> 00:05:12,080 And if you're lazy, you won't wanna answer a lot of questions about your program. 80 00:05:12,080 --> 00:05:15,400 So, make sure that you document your code well. 81 00:05:15,400 --> 00:05:18,550 Lazy or not, reducing the amount of busy work I need to do. 82 00:05:18,550 --> 00:05:21,710 Gives me more time to do the ever increasing list of things that 83 00:05:21,710 --> 00:05:23,140 I want to accomplish. 84 00:05:23,140 --> 00:05:27,580 Besides, it sure is rewarding to build something that's actually useful. 85 00:05:27,580 --> 00:05:30,750 Let's finish off this course by combining the unit converter and 86 00:05:30,750 --> 00:05:33,210 the daily exercise programs into this page as well.