By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,570 Members | 999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,570 IT Pros & Developers. It's quick & easy.

date/ month/ year format

100+
P: 232
i want to display it in date/ month/ year format

Expand|Select|Wrap|Line Numbers
  1. <td><?php echo date("d/m/y",($row[dob])); ?></td>
  2. output
  3. 01/01/70
  4. <td><?php echo $row[dob]; ?></td>
output
1977-08-09
correct date in data base is 1977-08-09
Aug 12 '09 #1
Share this Question
Share on Google+
7 Replies


MrMancunian
Expert 100+
P: 569
Split your date in 3 parts and change the order of those parts. Put it back together and echo it :-)

Expand|Select|Wrap|Line Numbers
  1. $datesplit = explode("-",$row['dob']);
  2. $datearray = array($datesplit[2], $datesplit[1], $datesplit[0]);
  3. $date = implode("-", $datearray);
  4. echo $date;
Steven
Aug 12 '09 #2

100+
P: 232
@MrMancunian
thanx for this valuable information but kindly explain me why my built in date function is not working
Aug 13 '09 #3

MrMancunian
Expert 100+
P: 569
Expand|Select|Wrap|Line Numbers
  1. date("d/m/y",($row[dob]))
works like
Expand|Select|Wrap|Line Numbers
  1. date(format, timestamp)
Most likely $row[dob] doesn't contain a valid timestamp and is set to null, which is 01/01/1970.

Steven
Aug 13 '09 #4

mwasif
Expert 100+
P: 801
It is better to use MySQL DATE_FROMAT() in your query.
Aug 14 '09 #5

MrMancunian
Expert 100+
P: 569
@mwasif
I think that better is quite subjective...Perhaps you can elaborate on why you think it's better?

Steven
Aug 14 '09 #6

100+
P: 232
@MrMancunian
my field name is dob and its datatype is date i think both function
date() and date_format need data type datetime but i am not sure about it kindly explain
Aug 16 '09 #7

mwasif
Expert 100+
P: 801
For DATE_FORMAT(), date and datetime both works. BTW, did you try DATE_FORMAT()?

@MrMancunian
Keep your PHP code clean. Why bother PHP if you can do things in MySQL
Aug 16 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.