Basic PHP Programming Tutorial 25: Time and Time stamps
Key Takeaways
Displaying time and timestamps in PHP
Full Transcript
hello and welcome to the 25th php tutorial in this tutorial we're going to be talking about time and various ways to display uh time formats and here i've just commented real quick a bunch of stuff about time and then also this link to time i mean there's just like there's a million different uh letters and stuff that we can use to denote all kinds of different stuff when you're making a date stamp and so you can find it all here is php.net is actually really good for just about every documentation type and with php i mean it's incredible so anyway there's that and i don't expect you to understand what this means just yet but i'm going to show you so going right on along we've got um the most basic way really to display time is just what's called a unix timestamp that's the number of seconds after january 1st 1970. so the way this is displayed let's just echo out unix time and then we'll make a break here and then we want to echo out um time and then no nothing in the brackets period uh actually let's just check out time so we'll just do that first and save it pop over here refresh unix time and then that's that's a unix timestamp just a large digit or integer and so that's not i mean that's nice it's good the point of unix times it's like you know the same for everybody and it's convertible and it's very universal is a good word for it but it doesn't look very pretty and if you're you know let's say you have a news site and you want to print out the time that something was posted or a forum or something like that if you print this out like doesn't really help anybody so instead what you can do is start to convert so how do you convert um unix time well i'm so glad you asked so what we can do now is let's go ahead and append some breaks to this so we'll just append um two breaks so we've got a line of space and what we'll do is we'll call our variable date we'll call it date stamp and that's going to equal date and within date you have two parameters the first parameter is how you want that date to show up so for now we'll just leave it running the next parameter is what you want to apply that to so say you had a variable that equal time you can put that variable in there like if you said like if you said unix or i'm sorry unix time oh my goodness unix time equals time right if you said that then you would uh you would throw unix time in here okay but really work for this we're just going to throw in time here so um so now we can specify how we want this time to be displayed if you type in if you want to type in a word like today is whatever you have to escape the characters there might be a better way to do this if you know the better way to do this go ahead let me know might be using maybe double quotes somehow i don't know but if you want to uh like say you wanted to just say the um you would have to do t h e like that and that will escape every single character because as we can see up here uh letters mean all kinds of different things so you don't want it um to be confused so with that let's just do um an easy one let's say we want to do this is the number of the month uh two digits and this is without any leading zeros let's do um so let's keep this fairly basic let's just do the month the day and the year so that's not too confusing let's just do a uh numerical month with the leading zero you can also get the numerical month without a leading zero so like if it's uh february uh this will be zero two and then this would just be uh two and so let's do month day year and let's just keep everything nice two digit format uh so we'll do uh m and then you can specify all kinds of different stuff like we could do m day uh year like that but most people are going to want to have like a slash probably so m day y okay so let's save that and let's put that and see what we get um oh we need to echo it out so first let's echo this out um echo and let's say date stamp colon and then we'll add a couple breaks and then we'll echo date stamp there put that up and we refresh and we get uh 6 27 13 which is in indeed the uh correct date for me so now what can we what else can we do with this obviously you can put like this you know we just got the month day in the year but then you can start doing um time formats and all kinds of fun stuff so let's go ahead and um throw some more stuff in here like if you want to do the month today of the year then let's do a space and actually let's change this up let's make it uh pretty crazy uh so let's say we want to do um so let's say we want to say like today is um let's say we want to do the day of the week full day of the week then the number of the month period and then a time stamp and then we even want to add in the time zone of that time stamp oh man it's going to get crazy in here so to do that uh let's start over we'll just make this empty so first we want the day of the month or i'm sorry the day of the week so that is going to be an l a lowercase l then we want to say so let's say we want it so it's going to say thursday the blank of um for today let's say um or actually yeah so let's say we want to say uh yeah today will be thursday the um 27th of june 2013. sorry this stuff gets kind of confusing after a while but i just want to show you how you can make a pretty complicated one so let's do uh so we wanted to say thursday so that's done space and then uh escape the t escape the h escape the e so it'll say the and then we want it to say uh the day of the month or the uh the numerical day and let's do the one without leading zeros right so number of the month so let's do j right so you don't want to say oh sixth of the month now you say the sixth or whatever in our case it's the 27th so it won't matter either way but uh it was a lowercase j so we'll do j and then to get that like uh to get that suffix so to speak i don't have it in my list but it's an actual it's an uppercase s so this will be like sixth the um second and so on so and then we want it to say of so again we need to escape the o escape the f then we want the month and we want the full month let's see if we yeah so we've got that with the uppercase f so the full month f then we want to go ahead and have a period so that's just going to appear you have to escape that now we want the hours minutes and seconds and for that let's go ahead and do the full one and uh again i don't have hours here but it's going to be uppercase h then we want to colon uh a lowercase i for the minutes and then just s for the seconds um easy way to remember this is just his uh so then we want to do uh the blanket on here time zone time zone is just e as you can see here identifies the time zone so e and that should be it it's totally possible that we type out something but we'll see what we get so we'll throw that up there let's refresh and now we've got it's thursday the 27th of june 904 american phoenix and this is actually corresponds to the server time so the time of the server is 904 you can also throw in like am or pm um all kinds of stuff like i've just got a few of these so like let's say we want to throw in the am so we can throw in um oops pop over here uh space a so let's save that and put that up come over here refresh so you can see okay it's not 904 35 am and you know you can keep refreshing and since it's like the unix stamp you know that'll keep going up and our seconds will keep going up and so on anyway those are the basics of time stamps the kind of letters that you can do and you can do anything with displaying a time stamp and if you want to read more about it you go to this php.net and then manual english function date or just type in this uh url if i remember to i'll put in the uh this video's description as well it's real helpful i mean they've got a ton of different ways that you can display stuff so it's pretty cool um so anyway as always thanks for watching and stay tuned to the next video
Original Description
Link to the full playlist:
http://www.youtube.com/playlist?list=PLQVvvaa0QuDcYpcjrNB43_iKqla5UeQw_
Sentdex.com
Facebook.com/sentdex
Twitter.com/sentdex
How to display time and format into various time formats.
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 37 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
▶
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
More on: Backend Performance
View skill →
🎓
Tutor Explanation
DeepCamp AI