 Hello and welcome. This is part three in a series. Be sure to watch the previous videos, otherwise you may be a little lost. But we're just looking at some commands, of many commands that you can run at your Linux shell, which in this case is Bash. Explain a little bit more about that in the first video, which hopefully you've watched. But today we're gonna be looking at the date command. So on pretty much all systems running, if you're running a Bash shell, you're probably have a date command available to you. Run that and it's gonna tell you the date. It's gonna tell you the day. So today is Monday. It is March 18th at the time of recording this. It is 8 a.m., 8.18 a.m. in 37 seconds. And I'm in Eastern Standard Time and it is 2024 at the time of recording this. That's great, that's very useful. What other options does it have? Well, I can say percent plus capital F, and sorry, I did that wrong. It's plus percent capital F, and it'll give me an abbreviated date as so. Another thing I can do is I can say H. What's that gonna do? Well, it's gonna give me the short version of the month. If I do capital M, it's going to tell me the minutes that we're currently at, right? It's 8.19. If I do a lowercase M, it's gonna tell me what month it is based on a numeric value. So instead of March, it's going to say three. If I was to do a capital H, it's gonna give me the hours in a 12-hour format, or no, I'm sorry, that's a 24-hour format. If I do capital I, it's gonna give it to me in a 12-hour format. So it's 8 a.m. But if it was 8 p.m., this version will still show 08 where this version would show 20 because it would be 200 hours. So we can do different things. We can also combine these. So for example, capital Y is a four-digit year. If I do lowercase Y is a two-digit year. So it's 2024. I can then do dash percent, and I can say M, and it will give me the month. If I don't want a dash, I can do a slash. If I want, I can do month slash percent, and I will do then do D for day slash, and I will do percent lowercase Y or capital Y. So how do I know all of these? Well, as I talked about briefly in the last video, almost all your programs that you're gonna run in your shell will have what's called a man page, a manual, if you will. Some are written better than the others, and good ones will give you examples in them as well. And some people complain about man pages, and it's just some are written well and some just aren't. Let's go ahead and look at the man page for date, and all you have to do is type in man and whatever command you want the manual for, in this case, date. And if we come in here, there's a lot of information. But right here you can see that we have all these different characters meaning different things. For example, percent lowercase A will be the day of the week in a three digit format, the abbreviate format. If you do capital A, it's going to be the full name. Lowercase B would be short version of the month. Capital B would be the long version of the month. If you do C, it's going to print it out, the local time as such, formatted like that. If we do capital C, it's going to give you the century. Basically it's like year, but it's going to be the two digits at the beginning rather than the end. So for cases 2024, it would be 20. Lowercase D is the month as a digit. If you do a capital D, it will print it out like this, month, day, and year with forward slashes. So you can come in here and you can see all these options and you can also create your own. A way, one of the very useful ones. And so also even has things like new line characters, which we'll talk about in a moment. You can do R. So you can create your own. You could do this manually, or by then they have an abbreviation for it with dash R, the epoch time. So if we do percent S, that's the number of seconds since 1970, you know, January 1st, 1970 at the beginning of the day, midnight. This is very useful and used a lot in programming. If you wanna calculate the time between one point and another, it's easiest to convert those to seconds and then convert them back using date command, which we may not get to in this video, but we probably will in a future video. I'm gonna go ahead and hit Q to get out of the man page, but let's go ahead and just type data command again. And what I can also do is I can do plus percent S. Again, will give me the number of seconds and every time I run it, if it's been at least a second, it's gonna give me a different number, right? This is the number of seconds since January 1st, 1970 at the beginning of the day. But I can also do again, capital Y for year. And I can put in here, I can say year and it will print year in the year. I can do year colon. Now, if I do a space, it's gonna give me a problem because it's thinking, because there's a space here that we've moved on to something different. So what you can do is, as we talked about in the very first video in the series, where we did backslash means take the next character, not a special character, but literally, I can say backslash and it will now print that as a space rather than looking at it as a new part of the command. So I can type things and I can say the day is, and then I can say D for day, or that's the 18th. Let's do, what do we say? Was it A for Monday? Yep, or capital A would be the day is Monday. So you can format the date in many different ways. But did you know date can be used to calculate stuff? And so you can use your script very smartly. Think about on your phone or in a calendar application. Lots of times you can say something like, schedule dinner for tomorrow or next Tuesday or three days from now. Well, the date command actually recognizes a lot of those type of things. And I'll just show you a few examples here. So what I can say here is I can say date, and if I say dash dash date equals and I can give it a date. So I can say, let's say 01 slash 01 slash 2024. It's going to print out Monday, January 1st, 12 a.m. Eastern Standard Time. So it took that date and told me, so now I know that the first of this year was a Monday. And if I just wanted that, I can now add on that percent, that plus percent, and what did we say, capital A? So now I know that the first of this year was a Monday. Now what if I was just put this? Okay, so it automatically expects it to be this year if you don't give it a year. So I can say, okay, what about this? So the second, January 2nd of this year was a Tuesday. I can say, okay, what about in the future? What about 502, at least at the future at the time recording this? I'm assuming by the time I post it, that's going to be a Thursday. Now I'm putting in certain dates here and I can also look at a year. I can say 2222, so that's way in the future. Well, that's going to be a Thursday as well. That's going to be a Wednesday. So I can figure out what day of the week, any date in the past or future is. Now I could also say something like tomorrow. And it's going, you know, so right now today is a Monday. If I do that, it tells me tomorrow is a Tuesday. And you can also say plus five days. It's looking five days from now. Five days from now is a Saturday or a Wednesday. And I can also say, okay, what is going to be the, that would be the, I meant to do a lowercase m for a month. So we'll still be in this month, but if I was to go, how many days? I'll do 22 days. I'll know that 22 days from now, we will now be in April. And of course we can always look at the man page for different outputs of that. You can also go backwards. So I hit control L to clear the screen. I can go, okay, 22 minus 22 days. I can, and it goes, oh, okay, that month was the second month, but I can also just see what the date was 22 days ago. And so it's very smart. Other options, I can say next Tuesday. Next Tuesday is going to be March 19th because it's tomorrow. So it sees the next Tuesday as the next Tuesday coming up. Let's see, I think I should be able to say last Tuesday. Last Tuesday was the 12th. So it's very, very smart and it can take a lot of different inputs. So if you are writing a script that needs to put the date into something, you can always have the user type something like this and it could be somewhat smart and you can figure it out. Now, something we haven't gone over yet is we've talked about putting things in the variable. So let's say I want to create a variable called name and I put in quotations, I can say Chris and then I can echo dollar sign name. We'll print that out. But if you want to put the output of a command into a variable, what you can do is I can create a variable called D for date. And then here I'm going to say inside the quotations dollar sign and then opening and closing parentheses. Now I can put a command or a group of commands inside here and whatever the output will be in that variable D. So I can say date. Now if I echo dollar sign D, it's going to output the date. Now I realize it's the date at the time of running this. So if I run it again, if I run the echo command again, it still, it hasn't moved forward at all. This is useful if you want to use a certain time stamp at the beginning of a script and use it multiple times later and match them up because if you run the date command multiple times, not only will that use extra system resources running that date command as opposed to just using a variable, but the seconds might change throughout that. So yeah, you can put that into a variable so I can say something like dash dash date equals tomorrow. And now if I echo dollar sign D, it will give me what tomorrow is. And again, I can put this, I can say plus percent. And what did I say? Is it capital D for day? I believe so. Echo dollar sign D. Oh no, let's run that again. Let's look at the man page real quick because I'm drawing a blank. And down here we will say capital A for the day. Now if I echo dollar sign D, it will say Tuesday. Now let's go into our script. Let's create a new script. Let's go ahead and just create a script called, we'll call it tomorrow. Again, we don't need the .sh. That's just letting the user know it's a shell script but the computer really doesn't care. Again, we're gonna start our line with the shebang line which as I talked about in a previous video is just saying what program to use to read the script. In our case, it's a bash script. So another thing to copy and paste things in most Linux terminals which the terminal is the application that displays the shell, you highlight it and on Linux, by default, you've already copied it. On most Linux systems, once you highlight something you have two clipboards that just went into one clipboard but to be sure you can hit control shift C because again, control C in the shell will kill the current running application it will cancel it but control shift C will copy that. So we can highlight and it's already copied to one clipboard and we can do control shift C to copy it. We can now go into our script here and I can hit control shift V and again, I'm using Vim. If you don't use Vim as your text editor, that's fine. I'm not going into you how to use Vim use whatever text editor you like. So I hit control shift V which normally control V in most applications would paste. Another option, again, once I highlight something so if I was just highlight this most Linux systems, that's already copied if you sent your click which if you have a wheel on your mouse if you click the mouse that's how you paste what you highlighted. So I can highlight something, click highlight something, click and so you can quickly copy and paste stuff without having to do any combinations on your keyboard there. Well, now I'm going to say echo tomorrow is dollar sign D. Now, new script, so I have to make it executable. I'm going to control L to clear the screen and give it the name of that. So I'm going to say tomorrow. Now dot slash again, the dot slash just means I'm writing a script that's in this current directory. Boom. So anytime I run that, it's going to tell me what tomorrow is. And if it was tomorrow, it would tell me that Wednesday would be the output. So this little look at the date command it is very useful. Again, it's very smart. I just showed you some examples of like next Tuesday, last Tuesday, five days from now, five days ago. You could probably say plus, well let's actually when you just not say maybe you should be able to say date equals plus one year. And sure enough, one year from today is going to be a Tuesday, it's going to be March 18th because it's the 18th. But today is Monday, next year, March 18th it's going to be a Tuesday. And there's the year. So you can do plus or minus years, plus or minus days, should be able to do weeks. Yep, we just jumped ahead. One week will be the 28th or 25th. And we can go back a week. So the date command is a lot smarter than you might think. Look through the man page for it. It actually isn't very long. It will tell you everything you need to know. And especially these formatting for the different abbreviations to get the output that you want for certain things. So yeah, filmsbychrist.com. That's Chris of the K. There's a link in the description of this video to my website. At my website you can search through my videos. There's also an option up in the top corner. If you click on it, it says software I believe and that will bring you to a section where you can get links to my GitLab page, my Git notes, but also a section that just says notes, which is every pay spin file I've made in the last, I think probably over 10 years. It's a section on my website where you can search through all those. And I go there all the time because that's where I remember stuff if I have to look stuff up. Anyway, I do thank you for watching. Please visit filmsbychrist.com. That's Chris of the K. Link in the description. You can also support me there. There's a support section with PayPal, LibrePay, Patreon, buy me a coffee. I would love your support. If not, I do thank you for watching. Be sure to like, share, subscribe and comment. And I hope that you have a great day.