Jump to content

Archived

This topic is now archived and is closed to further replies.

Moron

Problem with strtotime()

Recommended Posts

This code:

[quote]<?php

$lastjuly = strtotime("Last July 1");
echo $lastjuly;
echo date("m/d/Y", $lastjuly);

?>

.....returns the UNIX timestamp and 06/29/2001    :o

Anybody know why?

Now, if I change it to read "Last Monday," it returns 08/14/2006, so it works, but what's wrong with my syntax?

Share this post


Link to post
Share on other sites
[quote author=GingerRobot link=topic=104630.msg417415#msg417415 date=1155825752]
because you are echoing both the timestamp and the the formatted version?
[/quote]

Yes, but that's deliberate. Since I'm a total newbie, I tend to echo WAY too many things to see what I'm doing.  :D

The problem is that the formatted version should be giving me 07/01/2006, since that was the [i]last July 1[/i] that happened. Instead, it's giving me 06/29/2001.

See what I mean?

Thanks!

Share this post


Link to post
Share on other sites
Oh i see, sorry. I guess the string is not explicit enough. You could try last 01 July or something, but again, that might be too ambiguous.

You could try:
[code]
<?php
$month = date('m');
if($month >= 6){
$year = date('Y');
}else{
$year = date('Y') -1;
}

$lastjuly = strtotime("01 July $year");
echo $lastjuly;
echo date("m/d/Y", $lastjuly);
?>
[/code]

Share this post


Link to post
Share on other sites
[quote author=GingerRobot link=topic=104630.msg417425#msg417425 date=1155826271]
Oh i see, sorry. I guess the string is not explicit enough. You could try last 01 July or something, but again, that might be too ambiguous.

You could try:
[code]
<?php
$month = date('m');
if($month >= 6){
$year = date('Y');
}else{
$year = date('Y') -1;
}

$lastjuly = strtotime("01 July $year");
echo $lastjuly;
echo date("m/d/Y", $lastjuly);
?>
[/code]
[/quote]

Yep, that works. It seems to be a derivation of the "fiscal year" code you posted.

Outstanding!

And thanks.

:)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.