Reply to Re: Simple String To Date Question

Your name:

Reply:


Posted by ZeldorBlat on 09/08/07 20:11

On Sep 8, 1:57 pm, cppaddict <he...@hello.com> wrote:
> I have dates like "8/27" or "9/4", and I need to convert them to date
> objects.
>
> When choosing a year, we should go backwards until we find the first
> match. That is, if the script runs on Jan 1, 2008 and encounters the
> string "8/27", it should return a date for "8/27/2007".
>
> I've been playing around with strtodate and some other functions but I
> can't figure this out, and as there must be a simple solution I'd like
> to avoid writing a custom function.
>
> Thanks for any help,
> cpp

The year will always be this year or last year. So, try both and pick
the one that is before the current date:

$someDate = '8/27'

$lastYear = strtotime($someDate . '/' . date('Y'));
$thisYear = strtotime($someDate . '/' . (date('Y')-1));

$theDate = ($thisYear <= time()) ? $thisYear : $lastYear;

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация