Skip to content

Instantly share code, notes, and snippets.

@vimishor
Created December 18, 2012 22:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vimishor/4332595 to your computer and use it in GitHub Desktop.
Save vimishor/4332595 to your computer and use it in GitHub Desktop.
The clean and fast way for changing date format in PHP
<?php
$date = new DateTime('now');
echo $date->format('d/m/Y').PHP_EOL; // format: day/month/year
echo $date->format('m-d-Y').PHP_EOL; // format: month-day-year
echo $date->format('Y-m-d').PHP_EOL; // format: year-month-day
// add 3 days to current date and output using format year-day-month
echo $date->setTimestamp( strtotime('+3 days', $date->getTimestamp()) )->format('Y-d-m');
@xeoncross
Copy link

Also look at the PHP INTL functions for i18n and l10n methods of displaying dates. Not everyone is American.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment