Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP echo only month from record

Featured Replies

I've looked on google for this but can't find an answer, only lots of unrelated content. I'm echoing a date from my MySQL database using <?php echo $row_events['fromdate']; ?> which outputs 2013-12-12. but I need to echo only the month from this record. I know I can display the month from the server using <?php echo date("F"); ?> but not sure how to combine the two and display only the month from my database. Thanks

<?php

 

$parts = explode('-', $row_events['fromdate']);

 

echo $parts[1];

 

?>

 

if thats uk format or

 

<?php

 

$parts = explode('-', $row_events['fromdate']);

 

echo $parts[2];

 

?>

 

if it is USA format

  • Author

Awesome, thanks :) I just discovered substr so managed to get it working using <?php echo substr($row_events['fromdate'],5,2); ?> but your code works great too. Any idea how to get the date to display as the month name? I know it's usually echo date("F") but not sure how to work it into this code. Thanks for you help buddy

  • Author

Got this working now. I used

 

<?php $eventdate = $row_events['fromdate']; ?>

 

Then to display the month and day:

 

<?php echo date('M', strtotime($eventdate . '-1')); ?>

<?php echo date('d', strtotime($eventdate . '-2')); ?>

 

Hope this helps someone else and that its the correct way of doing it as I messed around with the '-1' and '-2' not really knowing what they do, but it works :)

Edited by drennan

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.