|
Posted by Jerry Stuckle on 11/21/06 14:18
meltedown wrote:
> Jerry Stuckle wrote:
>
>> meltedown wrote:
>>
>>> petersprc wrote:
>>>
>>>> You could work on the text:
>>>>
>>>> $date = '2006-11-19';
>>>> $newDate = substr($date, 0, strrpos($date, '-')) . '-01';
>>>>
>>>> meltedown wrote:
>>>>
>>>>> petersprc wrote:
>>>>>
>>>>>> You could do something like this:
>>>>>>
>>>>>> <?
>>>>>>
>>>>>> function firstDayOfMonth($str = '2006-11-19')
>>>>>> {
>>>>>> $day = date('l', strtotime(date('Y/m/01', strtotime($str))));
>>>>>> return $day;
>>>>>> }
>>>>>>
>>>>>> echo firstDayOfMonth();
>>>>>>
>>>>>> ?>
>>>>>>
>>>>>> Change the date format string if you want other information about the
>>>>>> first day of the month.
>>>>>>
>>>>>> meltedown wrote:
>>>>>>
>>>>>>> If I have an sql date, such as "2006-11-19" is there a way using
>>>>>>> either
>>>>>>> sql or php date and time functions to get the date of the the
>>>>>>> first day
>>>>>>> of the month ?
>>>>>
>>>>>
>>>>> Thanks, but I want the date, not the weekday. For 2006-11-19 it
>>>>> would be
>>>>> 2006-11-01
>>>>
>>>>
>>>>
>>>
>>> Yes I know but I'd rather not.
>>
>>
>> Why not? It's probably the most efficient way of doing it.
>>
>
> Could be, and it could be fine, but it treats a date datatype as a
> string datatype. I'd rather stick to strict datatypes which to me means
> its less likely to have some unforseen problem. I guess its just a
> habit I got from starting out with C++
I understand, and that's a very valid reason.
But in PHP there is no date datatype - unless you create a date class
yourself. It's handled as a string.
If you want to be really good about it, you could create a date class
and have it parse out the date from MySQL. I've done this before when
I've needed to do a bunch of stuff on dates. It did help simplify the
rest of the code (which a properly constructed class should do). But it
also added a little extra overhead to the process (which was also expected).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|