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.

Converting MySQL date to PHP format?

Featured Replies

I've got my dates stored in a MySQL table in TIMESTAMP format.

 

I then pull these dates from the table using PHP, and I can echo the TIMESTAMP date in PHP exactly as it appears in the MySQL table.

 

E.G.

2010-07-01 14:26:00

 

What I'd like to do is convert the TIMESTAMP format '2010-07-01 14:26:00' to something like '1st Jul'.

 

This is the code I'm using, but it keeps on displaying '1st Jan'?

 

$mySQLdate = mysql_result($result,$j-1,'date');
echo date( 'jS M', $mySQLdate );

date() takes a unix-timestamp as it's argument, not a SQL date string, what you need to do is convert it with strtotime()

 

echo date('jS M',strtotime($mySQLdate));

  • Author

Excellent, thanks for your help.

 

I'm a little confused as to how the PHP code was being processed then in my orignal example.

 

$mySQLdate = mysql_result($result,$j-1,'date');
echo date('jS M', $mySQLdate);

 

Was it ignoring the $mySQLdate variable in the

date('jS M', $mySQLdate)

statement, or giving this variable a new value based on the Unix Timestamp?

it was attempting to convert the string "2010-07-01 14:26:00" into an integer using php's Integer Casting, this results in 2010, in unix time this represents the time Thursday, January 1, 1970 12:33:30 am UTC (2010 seconds from the epoch)

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.