You are here: Re: PHP math with MySQL date format « PHP Programming Language « IT news, forums, messages
Re: PHP math with MySQL date format

Posted by bill on 10/14/07 17:16

C. (http://symcbean.blogspot.com/) wrote:
> On 14 Oct, 12:07, bill <nob...@spamcop.net> wrote:
>> Rik Wasmus wrote:
>>> On Sun, 14 Oct 2007 12:36:13 +0200, bill <nob...@spamcop.net> wrote:
>>>> (Don't froth at the mouth Jerry, this IS a PHP question - sort of <g>)
>>>> I have a SQL column with date format. In my PHP script I need to do
>>>> simple math on it, eg how many days past the date in the SQL record
>>>> are we now.
>>> Well, it could be solved quite easily in MySQL....
>>> SELECT
>>> something,
>>> datecolumn,
>>> DATEDIFF(datecolumn,CURDATE())
>>> FROM table
>>>> Do I need to convert it to a timestamp in order to do the math, or is
>>>> there an easier way ?
>>> Otherwise it's just a string, because PHP has no 'date' type. So either
>>> split it into components or indeed convert it to a timestamp (which
>>> would be easiest).
>> now back to PHP...
>> If I do the select as you noted above, after I have gotten the
>> row, what is the index..
>> e.g: $row['?????']
>>
>> bill
>> (The SQL docs are of no use on this)
>
> They're numbered from the left, but its much, MUCH more sensible to
> always use associative arrays (use var_dump to see what it currently
> shows).
>
> For a proper solution use aliases in the query:
>
> SELECT
> something,
> datecolumn,
> DATEDIFF(datecolumn,CURDATE()) AS days_diff
> FROM table
>
>
> C.
>
better,
Thanks

bill

 

Navigation:

[Reply to this 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

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