Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

MySQL date

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

TwiztedFake

Established Member
Impact
1
On the site I'm working on I store the date in a MySql table every time a member submits a form. The default format for DATE in MySql is YYYY-MM-DD but I want it to display as MM-DD-YYYY when its called to be displayed.

Is there a way to do this in PHP or should I just change it from DATE to something like VARCHAR, which kind of screws up with ordering by date.
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
TwiztedFake said:
On the site I'm working on I store the date in a MySql table every time a member submits a form. The default format for DATE in MySql is YYYY-MM-DD but I want it to display as MM-DD-YYYY when its called to be displayed.

Is there a way to do this in PHP or should I just change it from DATE to something like VARCHAR, which kind of screws up with ordering by date.


Store it as YYYY-MM-DD than use explode to rearrange it for PHP processing..

iNod.
 
0
Close
I just discovered that and am reading about it now.
 
0
Close
you can use strtotime( ) , see sample here
 
0
Close
I used a function to convert the date for displaying it on pages.

PHP:
function dateconvert($date) {
		list($year, $month, $day) = split('[-.]', $date); 
		$date = "$day/$month/$year"; 
		return $date;
		}

Then simply used the following where I wanted to display it.

$date = dateconvert($row["date"]);
echo $date;

It works so thought I'd share it.
 
0
Close
The date is stored in mySQL with format YYYY-MM-DD and that's normal behaviour.
You can use the mySQL date_format function in your query to display dates the way you want.

Example:
Code:
SELECT DATE_FORMAT(your_date_field, '%m-%d-%Y') as date_formatted
from your_table
This will display date like this: MM-DD-YYYY
 
0
Close
Why not use timestamp always and format it to whatever in PHP?
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back