convert w date to l format

This is a discussion on convert w date to l format within the PHP General forums, part of the PHP Programming Forums category; Um ... can anyone point me to somewhere that it explains this ... I am trying to convert a "int" (...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-06-2007
Steven Macintyre
 
Posts: n/a
Default convert w date to l format

Um ... can anyone point me to somewhere that it explains this ...

I am trying to convert a "int" (1 through 7) to a day name (Monday through
Friday) while in a loop with mysql results

I have tried $day = date('w', $day);

But this does not seem to work ... can anyone assist?


Kind Regards,


Steven Macintyre
http://steven.macintyre.name
--

http://www.friends4friends.co.za
Reply With Quote
  #2 (permalink)  
Old 01-06-2007
Stut
 
Posts: n/a
Default Re: [PHP] convert w date to l format

Steven Macintyre wrote:
> Um ... can anyone point me to somewhere that it explains this ...
>
> I am trying to convert a "int" (1 through 7) to a day name (Monday through
> Friday) while in a loop with mysql results


What happened to the weekend? I'd hate to lose the weekend!!

> I have tried $day = date('w', $day);
>
> But this does not seem to work ... can anyone assist?


That's because the date function expects a timestamp.

What you want is an array, nothing more complicated than that.

$days = array(1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
7 => 'Sunday');

$day = $days[$day];

-Stut
Reply With Quote
  #3 (permalink)  
Old 01-06-2007
Robert Cummings
 
Posts: n/a
Default Re: [PHP] convert w date to l format

On Sat, 2007-01-06 at 14:46 +0200, Steven Macintyre wrote:
> Um ... can anyone point me to somewhere that it explains this ...
>
> I am trying to convert a "int" (1 through 7) to a day name (Monday through
> Friday) while in a loop with mysql results
>
> I have tried $day = date('w', $day);
>
> But this does not seem to work ... can anyone assist?


Something like:

<?php

$monday = strtotime( "next monday" );
for( $i = 0; $i < 7; $i++ )
{
echo date( 'w', $monday + (24 * 60 * 60 * $i) )."\n";
}

?>

Cheers,
Rob.
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
Reply With Quote
  #4 (permalink)  
Old 01-06-2007
Robert Cummings
 
Posts: n/a
Default Re: [PHP] convert w date to l format

On Sat, 2007-01-06 at 12:59 +0000, Stut wrote:
> Steven Macintyre wrote:
> > Um ... can anyone point me to somewhere that it explains this ...
> >
> > I am trying to convert a "int" (1 through 7) to a day name (Monday through
> > Friday) while in a loop with mysql results

>
> What happened to the weekend? I'd hate to lose the weekend!!
>
> > I have tried $day = date('w', $day);
> >
> > But this does not seem to work ... can anyone assist?

>
> That's because the date function expects a timestamp.
>
> What you want is an array, nothing more complicated than that.
>
> $days = array(1 => 'Monday',
> 2 => 'Tuesday',
> 3 => 'Wednesday',
> 4 => 'Thursday',
> 5 => 'Friday',
> 6 => 'Saturday',
> 7 => 'Sunday');
>
> $day = $days[$day];


That's not locale portable :B

Cheers,
Rob.
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
Reply With Quote
  #5 (permalink)  
Old 01-06-2007
Jochem Maas
 
Posts: n/a
Default Re: [PHP] convert w date to l format

Robert Cummings wrote:
> On Sat, 2007-01-06 at 14:46 +0200, Steven Macintyre wrote:
>> Um ... can anyone point me to somewhere that it explains this ...
>>
>> I am trying to convert a "int" (1 through 7) to a day name (Monday through
>> Friday) while in a loop with mysql results
>>
>> I have tried $day = date('w', $day);
>>
>> But this does not seem to work ... can anyone assist?

>
> Something like:
>
> <?php
>
> $monday = strtotime( "next monday" );
> for( $i = 0; $i < 7; $i++ )
> {
> echo date( 'w', $monday + (24 * 60 * 60 * $i) )."\n";
> }
>
> ?>


let do a merge of Robbert and Stut ;-) a mindmeld of sorts.

<?php

$mon = strtotime('next monday');
$day = 4 * 60 * 60;
$days = array();

for ($i = 0; $i < 7; $i++)
$days[$i] = date('w', $mon + ($day * $i));

// now you have a localized array of day names, that you can
// use in your output [loop?] in the way that Stut described.

>
> Cheers,
> Rob.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:52 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0