How To Automatically Add Dates in Google Sheets

Learn how to automatically add timestamps and dates in Google Sheets using App Script. This video covers both automatic date entry on sales input and creating a custom menu for manual date insertion.

Let's add dates semi automatically, where if we want to enter a sales number here, we want to have like a timestamp or a date here that we entered it, and you could do today, hit enter, copy, and then paste special values only. Absolutely. You could do that. You could do it now even, and however you format . This cell you can do by date here and just have dates. But what if we want like a timestamp ? Maybe we add something here. We want like a full timestamp or something else and we don't want to have to enter that. We just want Andy 44 and enter the date.

Go up to Extensions app script . I'm gonna show you a couple ways to do this. One way is just to use the on edit. We're gonna add an E or event here. This is just a variable that is going to have some really cool data . For example, we can know the row we're on variable row equals event range GI row. We can know what column we're on. Variable column equals event range . Dot get column, and if row is greater than one, meaning we're not on the hetero row, and column is equal to two, there's two equal signs there. Then we're going to do something which is we have just entered the sales, so we wanna put the date here.

A date is in column C, so we say spreadsheet app, get active spreadsheet . That's just getting the whole file. Get active sheet . That is this particular sheet one. If we want to actually name sheet one. Sheet name equals spreadsheet . App dot get active sheet , get name and sheet. Name needs to also equal sheet one. So we know that this active sheet . Is sheet one. So we do got get range . The row we're on column three because that's the C column. And we only want one co, one row, one column size. So we do one column one and we do set value new date.

Now we're gonna set that new date. Is going to be a whole timestamp . Maybe we don't want that. So we go variable today, date, we can just name that anything we want and we say new date. Now we want to format it so we go utilities, format , date. We put the time zone we want, we put the format we want, which may be. Just like year, year, year, month, month, dayday. So this is just letters like year, month, day, month is capital M, lowercase M is minutes. And that is the exact format we want here. So we set our value to this today date, our variable here. Let's add a date. Let's call that add date at the top.

Now, once we save this, we don't have to do anything else for this on edit function to work. If we just go over here and start adding Andy and 55 sales, there's our date, and that will automatically add the date. I wanna show you one more thing. I went to better sheets at co slash snippets to grab this function , this custom menu function . I'm gonna add it up here at the top and when this is open, so this function on open X, just like on edit, but it only happens when you open the sheet. We are gonna create a menu called Date Menu, and we're gonna write add date to sell. We're gonna create a function called add date to sell. What's this gonna do is gonna have give us a new F menu up here to add a function .

So let's add that function here. Function . Add date to sell and what is it gonna do? Well, we're gonna take the spreadsheet , we're gonna get the active range that we're in. Actually, I think we need to do active spreadsheet , get active range wherever we are. That's gonna be one cell. We can set that value as new date. And again, if we want to format this. All we have to do is add a little variable up here. We can actually take this exact same thing down here, copy and paste it. If we want this exact format and instead of new date here, we put in our variable today date and we're gonna save everything or click this save project to drive. We're going to close it. Go back to our sheet and hit refresh or reopen close and open it again.

After we've saved our app script , I'm gonna. Make it a little smaller here, and at the very top you can see extensions help, accessibility, and then date menu add date to sell. So any cell that I'm in, I can add today's date. It's gonna run a script. I need to authorize the very first time I run this and it has entered the date in that cell. I can do it again. Date add date to sell. This offers me a little bit different than a totally automatic thing from this add sales date. Again, this works Andy and do 88, and it's gonna add the date, but this date menu lets me add date anywhere, and it's as simple as that. If I have multiple cells selected, it's gonna add that date multiple

times, which is pretty cool, right? But if that's not something you want to do, you can totally edit this to have a bunch of ifs and say, if this is too many cells , this way or that way. You can do that. That's gonna be a little more complicated. I do recommend going and taking my spreadsheet , course, spreadsheet automation 1 0 1 over@bettersheets.co. Check out the courses, check out better spreadsheet automation 1 0 1. It's a really cool course that gets you into the basics within like three hours of total course time. And then it gives you a ton of examples, like hours and hours, hours of examples of how to use. App script and how to do it over and over and over again to do so many cool projects. And that's how I learned by just doing a bunch of projects.

And hope you can learn too. You are watching better sheets here on YouTube. Make sure you check out this video or this video and subscribe right now to get more tips, tricks, how tos, get more out of your Google sheets than you ever have before. I'm excited to be making a ton more videos here. Ask me questions down in the comments and I will answer them in future videos. But for right now, right here, one of these videos is gonna be your next Google sheet.