TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   How to covert the date into dd-mon-yyyy format? (http://www.talkphp.com/absolute-beginners/4697-how-covert-date-into-dd-mon-yyyy-format.html)

sandhyagupta 07-07-2009 12:20 PM

How to covert the date into dd-mon-yyyy format?
 
Hi

I am fetching the date from a particular table. now i wanna convert that date into dd-mon-yyy(eg: 07-jul-2009)format before displaying it.How do i do this?

PHP Code:

$sql_stmt1 "SELECT * FROM job_posting WHERE posted_by like '%$nickname%' ORDER BY job_posted_on DESC";

$result1  mysql_query($sql_stmt1$conn) or die(mysql_error());

while (
$row1_array mysql_fetch_assoc($result1))
{    
      
$postedby $row1_array["posted_by"];  
      
$postid $row1_array["post_id"];
      
$position $row1_array["position"];
      
//echo '<a href="http://www.konanakunteokkoota.org/applyhereforjob.php?username='.$username.'&jobid='.$postid.'">'.$row1["position"].'</a>';  
  
      
$joblevel $row1_array["job_level"];
      
      
$jobpostedon $row1_array["job_posted_on"];
      
//$convert1 = CONVERT(VARCHAR(11), GETDATE(), 106) AS [DD MON YYYY];


This is just the part of my code.

Thanks in advance.

codefreek 07-07-2009 01:37 PM

PHP Code:

<?php
function formatdate$s )
{
return 
date"d-m-Y"strtotime$s ) );
}

// how to use this function

echo formatdate$result"DateUpdated" ] );
?>

strtotime converts arbitrary strings to date and time value that can be used with other date related functions. date function formats a given date and time value back to a string.


This query will help:

PHP Code:

$query "SELECT *, DATE_FORMAT( DateUpdated, '%d-%m-%Y' ) AS FormattedDate FROM CharacterStats ORDER BY ID ASC"


The above query returns one additional column called FormattedDate that contains the DateUpdated in the desired format.


http://php.net/strtotime
http://php.net/manual/en/function.date.php


All times are GMT. The time now is 06:59 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0