1 00:00:00,240 --> 00:00:00,810 All right. 2 00:00:00,810 --> 00:00:05,980 We've got one more topic around dates and times, and it's going to seem a little confusing up front. 3 00:00:06,000 --> 00:00:11,640 There is a whole other data type, very similar to date time called time stamp. 4 00:00:11,730 --> 00:00:15,300 So time stamps combine a date and a time. 5 00:00:15,300 --> 00:00:23,640 If we go to the docs and look at the page around time stamps, it basically looks just like a date time, 6 00:00:23,640 --> 00:00:25,140 which we've already seen. 7 00:00:25,230 --> 00:00:26,700 Take a look right here. 8 00:00:26,940 --> 00:00:32,400 It says the time stamp data type is used for values that contain both date and time. 9 00:00:32,490 --> 00:00:37,680 The date time type is used for values that contain both date and time. 10 00:00:38,070 --> 00:00:40,260 So what is the difference? 11 00:00:40,800 --> 00:00:42,060 There's really two pieces. 12 00:00:42,060 --> 00:00:45,210 One is that a time stamp takes up less storage. 13 00:00:45,210 --> 00:00:50,220 It's a smaller thing in memory, which is a trend for all of these different types we've covered, right? 14 00:00:50,250 --> 00:00:56,280 Tiny end versus end versus big int or double versus float versus decimal. 15 00:00:56,400 --> 00:01:03,210 In this case, time stamps are smaller, but that's because they support a smaller range of dates, 16 00:01:03,210 --> 00:01:05,040 a much smaller range of dates. 17 00:01:05,069 --> 00:01:14,610 Look at the minimum 1970, January 1st, 1970, and then the maximum is January 19th of 2038 at three 18 00:01:14,610 --> 00:01:16,770 1407 seconds. 19 00:01:16,950 --> 00:01:22,750 Whereas a date time can go from the year 1000 up to the year 999,000. 20 00:01:22,770 --> 00:01:24,690 So that's an important difference. 21 00:01:24,780 --> 00:01:28,260 If we just think about what we're what we might be storing. 22 00:01:29,010 --> 00:01:34,230 It might narrow down the type we would use if we're storing somebody's birthday. 23 00:01:34,530 --> 00:01:40,730 Well, a timestamp maybe doesn't make sense unless we know all of our users were born after 1970. 24 00:01:40,740 --> 00:01:43,410 We probably would want to use a date time. 25 00:01:43,860 --> 00:01:49,680 But if we were trying to store the time something was most or most recently updated at, or when a comment 26 00:01:49,680 --> 00:01:56,670 was created or a user account was created, or somebody liked an Instagram post or whatever, some sort 27 00:01:56,670 --> 00:02:02,880 of interaction, an event occurred, well, a timestamp will work just great for that and it takes up 28 00:02:02,880 --> 00:02:03,810 less space. 29 00:02:04,200 --> 00:02:05,700 So it is confusing. 30 00:02:05,700 --> 00:02:06,880 There's no way around it. 31 00:02:06,900 --> 00:02:10,030 They look and behave the same most of the time. 32 00:02:10,050 --> 00:02:14,040 Let me show you an example of working with time stamps in the shell. 33 00:02:14,370 --> 00:02:17,760 We've got all these different functions that also work with time stamps. 34 00:02:17,760 --> 00:02:25,530 And technically, when we did now earlier, if I did select now, I said, this is a date time. 35 00:02:25,530 --> 00:02:27,900 It's actually a time stamp, not a date time. 36 00:02:27,900 --> 00:02:33,870 But they are essentially interchangeable when we're working with a date time or time stamp that overlap 37 00:02:33,870 --> 00:02:35,670 in the same range, right? 38 00:02:35,700 --> 00:02:41,520 This is right now today, if I express this as a date, time or time stamp, it will look exactly the 39 00:02:41,520 --> 00:02:42,060 same. 40 00:02:42,240 --> 00:02:45,360 So I can show you that if I did time stamp. 41 00:02:47,000 --> 00:02:50,160 I can take this and turn it into a timestamp. 42 00:02:50,180 --> 00:02:51,710 We're not going to notice anything. 43 00:02:52,400 --> 00:02:54,350 It looks like a time stamp. 44 00:02:54,950 --> 00:02:58,430 We also have time stamp and time stamp. 45 00:02:59,160 --> 00:03:05,360 If we can do math with timestamps, but at the end of the day, it's just another format for storing 46 00:03:05,360 --> 00:03:06,800 a date with a time. 47 00:03:06,800 --> 00:03:10,990 We just have a much narrower range that we can store those dates for. 48 00:03:11,000 --> 00:03:14,630 But it comes at the benefit of taking up less memory. 49 00:03:14,750 --> 00:03:16,460 Confusing, yes. 50 00:03:16,550 --> 00:03:18,890 Hopefully I clarified the difference. 51 00:03:19,280 --> 00:03:24,650 In the next video, I'm going to show you how we can use timestamps and date time and get some auto 52 00:03:24,650 --> 00:03:28,580 updating functionality, some really fancy stuff when we create a table.