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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple php_date question

Status
Not open for further replies.

flyingsheep

Technical User
Apr 24, 2004
15
US
i need to use the date() function, however, the date must be formatted like this: 011304 if the date was 01/13/04, how should i do this, also, is there a way to only return the first few letters of the date() function, if so, how, thank you very much in advance
 
date("mdy");

what you mean by letters? the first letters of the day value(ie wed, thu)? then use "D"...

date("D");

the manual has all the answers

Bastien

Cat, the other other white meat
 
can help you if you are passing a non date to php.

But it is best to make sure that you are actually using a date field in your database.

I used the above function eventhough I had a date field in my database and still required this function because the date() function did not co-operate [smile]

JR
(In need of a cool signature)
 
here is what i need, this is all for homepage if you need the source, what i need to do is; use the date() php function to change the following date formats:

27-Jun-04

sun2004 (where only the year changes)

062704 (this is 06/27/04)

and i also need a counter which increases by one every day but is not in fact a date, for example, today is 23 on the counter but the date is 27.

i think i could do this in php, but i am not sure how, can someone point me in the right direction?

thanks in advance
 
Let's not muddy the waters about the automatic increment question. You've already started a thread on that.



About dates....as Bastien has indicated, PHP's date() function can output the current date in a custom format.

And as JRBeltman has pointed out, you can use strtotime() to convert a date string to a number date() can use as its second optional input.




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I don't know in what time zone you are, but here on the US East Coast it is the 29th, not the 27th.
Please clarify:
use the date() php function to change the following date formats:

27-Jun-04 to what?

sun2004 (where only the year changes) to what?

062704 (this is 06/27/04) to what?

The counter is simple. You need only define the relative start date/time and subtract it from the current date.
Code:
$startDate = strtotime('2004-06-05 09:20:00');
# difference in second divided by seconds/minutes/hours
$var_days = (time() - $startDate) / 86400;
echo (intval($var_days));
 
im sorry, those dates are old, but i want to have the current dates, so that they change daily
 
so that

27-Jun-04 becomes 28-Jun-04

sun2004 becomes sun2005 (once a year)

062704 becomes 062804
 
The first and the third can be handled by simply having PHP dynamically produce the content of the page. Your users don't point their browsers to an HTML file -- they point their browsers to the script.

Then include an invocation of date() with the appropriate date format string. The date string will be appropriate to the current date.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top