0

i am having a problem with php and mysql. i have database in which is column Date(Y-M-D) Date is actual date field no varchar
And what i want is to change that "number" to name of that current month. For example:

2014-07-06

  • 2014-07-06 / 8:00 / Need for speed 3D / Kino

2014-07-05

  • 2014-07-05 / 8:00 / Need for speed / Kino

2014-06-06

  • 2014-07-06 / 8:00 / The Movie / Kino

ineed change that bold date to MONTH name (what i am expecting) :

July

  • 2014-07-06 / 8:00 / Need for speed 3D / Kino
  • 2014-07-05 / 8:00 / Need for speed / Kino

June

  • 2014-07-06 / 8:00 / movie / Kino
  • 2014-07-05 / 8:00 / second movie / Kino

My code:

$result = mysql_query("SELECT hlavni.datum_expirace, hlavni.priloha, hlavni.nazev,
vedle.misto
FROM hlavni
INNER JOIN vedle ON hlavni.sekce = vedle.idecko WHERE vedle.idecko IN ( 6, 7, 8, 15, 14,
16, 17 ) ORDER BY `hlavni`.`datum_expirace` DESC, `hlavni`.`priloha` ASC");
//fetch tha data from the database 
$currentDate = false;
while($row = mysql_fetch_array($result))
{
if ($row['datum_expirace'] != $currentDate){
echo
'<strong>' .  
$row['datum_expirace'] . 
'</strong>' ;
$currentDate = $row['datum_expirace'];
}
echo 
'<ul><li>' . 
$row['datum_expirace'] .
'</li><li>' .     
$row['priloha'] . 
'</li><li>' . 
$row['nazev'] .
'</li><li>' .     
$row['misto'] . 
'</li></ul>'; 
}  
user3197269
  • 93
  • 3
  • 12

1 Answers1

0
echo date('F', strtotime($row['datum_expirace']));

strtotime converts from the string to a date/time.

date('F') shows the date as the month name.

Written to be more in-line with your actual code example :

$cMonth = date('F', strtotime($row['datum_expirace']));

if ($cMonth != $currentDate)
{
    echo '<strong>' .  $cMonth  . '</strong>' ;
    $currentDate = $cMonth;
}

Update

Based on the comments, this might be better.

setlocale(LC_TIME, 'fr_FR'); //CALLED ONCE - with whatever language you need.

then

$cMonth = strftime('%B', strtotime($row['datum_expirace']));

See also :

PHP Date function output in Italian

PHP date() in foreign languages - e.g. Mar 25 Aoû 09

Community
  • 1
  • 1
DragonYen
  • 958
  • 9
  • 22
  • Happy to help. Feel free to accept the answer if it takes care of the problem =) – DragonYen Mar 26 '14 at 13:32
  • oh i will :D but right now i must wait 3 mins for accepting your answer – user3197269 Mar 26 '14 at 13:36
  • All this time here, and I didn't know there was a wait for approving answers. Anyhow, like I said, happy to help. Good luck with the rest of your project! =) – DragonYen Mar 26 '14 at 13:37
  • Can i have one more question ? i cant find how to set lc_time_names :( Do you know how this work ? or is there a way to rename a Name of the month ? – user3197269 Mar 26 '14 at 14:03
  • I think this will help : http://stackoverflow.com/questions/1328036/php-date-in-foreign-languages-e-g-mar-25-aou-09 -- Will update the answer. – DragonYen Mar 26 '14 at 14:13
  • i already did that :D but anyway... thank you ^^ Now i have problem with coding >.< when i change coding the MONTH name will be right BUT the rest of the text is messed up ... and when i revert changes then MONTH name is messed up and everything else is right xD – user3197269 Mar 26 '14 at 14:31
  • Check the first link (about Italian) the accepted answer shows how to switch to Italian and right back -- so that setting the local doesn't affect other functions. Maybe that would help? – DragonYen Mar 26 '14 at 14:41
  • well when i set: header('Content-Type: text/html; charset=utf-8'); the MONTHS names are messed up BUT when header is not set: MONTHS are perfect but the rest of the text is messed up – user3197269 Mar 26 '14 at 14:48
  • I don't really have to work much with localization/character sets -- so I don't know the answer off the top of my head, sorry. Might be worth posting a new question if you can't find the answer. – DragonYen Mar 26 '14 at 14:52