Jump to content

Problem with strtotime()


Moron

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?

Link to comment
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!
Link to comment
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]
Link to comment
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.

:)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.