Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the Year...trouble !! pls Help 1

Status
Not open for further replies.

Forri

Programmer
Joined
Oct 29, 2003
Messages
479
Location
MT
Hi all

i'm using the folwowing:

$DATE_CURRENT = date("n,d,Y");

$TEMP_DAY = date("d", mktime(0,0,0,$DATE_CURRENT));
$TEMP_MONTH= date("n", mktime(0,0,0,$DATE_CURRENT));
$TEMP_YEAR = date("Y", mktime(0,0,0,$DATE_CURRENT));

Where the Year, Month, day can vary as i will change them often! The Month and day are stored perfectly but the Year doesn't! it stays 2004!!! what's wrong

pls somebody help!

Thanks
Nick

 
I am frankly suprised that you are getting correct results for any part of that.

mktime() requires the input of discrete date parts. You cannot substitute a comma-delimited string for a set of discrete inputs.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
ok! so how would you go about it! am didn't understand much the discrete part!

Thanks
 
mktime() requires that you pass to it the following as input parameters:[ul][li]a seconds number[/li][li]a minutes number[/li][li]an hours number[/li][li]a day of the month number[/li][li]a month of the year number[/li][li]a year number[/li][/ul]

All of these numbers must be single values. You cannot substitute a string with some commas and numbers in it for three of the input parameters. You can omit values, in which case mktime() fills in what you've left out using the current date's values. And this is what is happening in your code. You're passing a seconds number, a minutes number, an hours number and a string, so mktime() is filling in the missing parameters with default values.


I'm not sure exactly what you're trying to do or what you're going to do with the numbers.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
oh!! I Think your perfectly right! i'll try! get back to you!
Thanks for now!
 
So how can i retrieve the month, day and year of a date...my DAte!!

Thanks again
 
Hi Forri,

I guess you could do this:

$CURRENTDAY = date("d");
$CURRENTMONTH = date("n");
$CURRENTYEAR = date("Y");

$TEMP_DAY = date("d", mktime(0,0,0, $CURRENTMONTH, $CURRENTDAY, $CURRENTDAY ));
$TEMP_MONTH= date("n", mktime(0,0,0, $CURRENTMONTH, $CURRENTDAY, $CURRENTDAY));
$TEMP_YEAR = date("Y", mktime(0,0,0, $CURRENTMONTH, $CURRENTDAY, $CURRENTDAY));

This should give you what you need.

------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
I would just use getdate() and fetch all the parts at once:

Code:
<?php
$my_date = '2004-03-02 11:46:00';

$date_array = getdate(strtotime($my_date));

print '<pre>';
print_r ($date_array);
?>

Returns:

Code:
Array
(
    [seconds] => 0
    [minutes] => 46
    [hours] => 11
    [mday] => 2
    [wday] => 2
    [mon] => 3
    [year] => 2004
    [yday] => 61
    [weekday] => Tuesday
    [month] => March
    [0] => 1078249560
)

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top