Finding month, weekday, day of the year for any date valueFrom a future date, past date or present date we can get different details like month name , weekday, month number, weekday number, day of the month etc by using getdate() function in PHP. This function takes time stamp of the required date as input and returns an array of details for that date.
By taking time stamp as input we can also use date() function to get the month name, day of the week etc of any date value. This we will discuss at the second part of this tutorial. Now let us discuss on getting date details of any future or past using getdate() function.
Here is the syntax of getdate() function.
$d_var=getdate([timestamp]);Here timestamp is he optional argument by which we have to give the timestamp of the required date. By default it takes the current date and time as time stamp. Getdate function returns an array with different elements listed here.
"mday" - day of the month
"wday" - day of the week, numeric (1 for Monday)
"mon" - month, numeric (08 for August)
"year" - year, numeric - like 2008
"yday" - day of the year, numeric; i.e. "256"
"weekday" - day of the week, textual, full; i.e. "Friday"
"month" - month, textual, full; i.e. "August"
Let us take one example and see how to find out all the above values for a date
You can see how the above code is used to get different values of a date. Here mktim() function is used to generate time stamp of the given date with hour, minute and second values and then the same time stamp is used as input to getdate function to get the date array.
Click for more tutorial on Date & Time functions and Applications
PHP Date & Time functions
PHP Date Timestamp and generating date & time in different formats
Validating Date: Checking if date is correct or not by using checkdate()
PHP Date Today: Getting current date, week day and month
PHP yesterday and previous 7 days from today
Vaious date formats to use in date function and class
Time stamp generator: Use any date and time and generate timestamp
Date selection drop down list box for users to select
mktime function to generate time stamp
Difference in Two dates by using mktime function
Finding month, weekday, day of the year etc for any date value
Breaking the date string to get month date and year using array
More On Date Object
PHP Date & Time class creating and examples of uses
Creating a date interval object and using with php date object
Adding date interval to date object to create new dates
Difference in date by using diff function and using date object
Add or subtract from date object using modify function
Changing parameters of the date object by using setdate function
updating time for a date object to a new value
Gettign the time zone setting of the server
Setting the default time zone of server
Array of time zones available for setting ( total list )
Getting time in seconds elapsed from Epoch time
Local time of the server or different time zones by using localtime() function