★ wanayoo — archive 1999 http://www.php.net/manual/function.getdate.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Date/time
Quick Reference
Date/time
* checkdate
* date
* getdate
* gettimeofday
* gmdate
* gmmktime
* gmstrftime
* microtime
* mktime
* strftime
* time
Manual: getdate
View the source code for this pageSearch the site



Previous page
 date
gettimeofday 
Next page


getdate

getdate -- Get date/time information

Description

array getdate(int timestamp);

Returns an associative array containing the date information of the timestamp as the following array elements:

  • "seconds" - seconds

  • "minutes" - minutes

  • "hours" - hours

  • "mday" - day of the month

  • "wday" - day of the week, numeric

  • "mon" - month, numeric

  • "year" - year, numeric

  • "yday" - day of the year, numeric; i.e. "299"

  • "weekday" - day of the week, textual, full; i.e. "Friday"

  • "month" - month, textual, full; i.e. "January"


User Contributed Notes: getdate



07-Sep-1999 07:51
Try this...
$date = getdate();
print "$date[minutes]";



olip@xzone.pl
16-Sep-1999 03:19
If you need something like today() function - just use that:
$today = date( "Ymd", time() );



smelecat@narcolepsy.dhs.org
26-Nov-1999 02:06
This makes a live clock.
$date = getdate();
$minutes = $date['minutes'];
$hours = $date['hours'];
$tz="EST"; /* Set your time zone here */
/* initialize $ampm */
$ampm="AM";
if ($hours > 12) {
    $hours=$hours-12;
    $ampm="PM";
}
/* Fix minutes so that minutes 1-9 have 2 digits */
if ( $minutes < 10) {
    $minutes="0$minutes";
}
/* Output: H:M AM/PM TIME ZONE */
print "$hours:$minutes $ampm $tz";



matt@studio77.com
12-Dec-1999 03:18
OOPS! Try again...

$today = getdate();
$month = $today[month];
$mday = $today[mday];
$year = $today[year];
echo "$month $mday, $year";




ems@itg.net
14-Feb-2000 10:28
*Note* - Month and day are NOT zero-filled, so be careful when inserting dates generated by getdate(time()) into a database.


mactari@hotmail.com
20-Feb-2000 01:31
Welp, while we're on the subject of examples with dates, I've had to shove the current time/date into a mySQL datestamp using php3, and here's the code for that datestamp's creation (hacked from the examples above, more or less):
$today = getdate();
$mon = $today[mon];
$mday = $today[mday];
$year = $today[year];
$minutes = $today[minutes];
if ( $minutes < 10) {
    $minutes="0$minutes";
}
$hours = $today[hours];
printf("%s-%s-%s %s:%s:00", $year, $mon, $mday, $hours, $minutes);
</php>


zparker@rpinteractive.com
06-Mar-2000 03:14
Re: timestamping w/ php + mysql.

If you're writing a php script and just want a quick timestamp for mysql, there's an easier method.
Create a field of type datetime, and then do the following:

<BLOCKQUOTE> insert into blah (blah, tstamp) values ('blah', NOW()); </BLOCKQUOTE> of course, if you're doing something more complex than timestamping, then you'll need to use the php method. but for timestamping, this is less hassle. ;)


mdchaney@michaelchaney.com
20-Mar-2000 09:49
Inserting date/time values into MySQL does NOT require 10 lines of code for each date. Just use the "date" function here in PHP to make a MySQL-friendly field:
$startdate=date('Y-m-d');
Use the optional second argument to specify the time (other than "now") to be inserted. If you want to insert into a date/time field, use the following:
$enddatetime=date('Y-m-d H:i:s');
Again, use the second argument to specify an exact time.


ian@wildwebservices.com
25-Mar-2000 12:36
Using MySQL/PHP3. Trying to use a TIMESTAMP table field type to specify when a record was last updated. tried:
$datearray = getdate ($myrow['timestampfield']) ;
but since it's read back as a string instead of an integer, getdate complains. Thoughts?


ian@wildwebservices.com
25-Mar-2000 12:39
I thought of trying
$myint = atoi($myrow['timestampfield']) ;
but doesn't look like atoi is supported... I get an error saying it's an unknown function. Anything else out there to convert a string to an integer?


erl@voxi.com
04-Apr-2000 06:38
For the sake of completeness, the description should say that the numeric weekday (wday) goes from 0 (Sunday) to 6 (Saturday).


 About Notes


Previous page
 date
gettimeofday 
Next page



Site Statistics


Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.