TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-07-2009, 12:20 PM   #1 (permalink)
The Wanderer
 
sandhyagupta's Avatar
 
Join Date: Jun 2009
Posts: 20
Thanks: 4
sandhyagupta is on a distinguished road
Default 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.
sandhyagupta is offline  
Reply With Quote
Old 07-07-2009, 01:37 PM   #2 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

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
codefreek is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Access Date problems. mtsang Absolute Beginners 4 06-27-2009 04:59 PM
help me figure out this date thing sarmenhb Absolute Beginners 5 09-15-2008 04:20 PM
Need more ideas for date and time class Wildhoney General 2 01-18-2008 02:22 PM
Two Different Ways to Format the Time CMellor Tips & Tricks 0 09-24-2007 11:12 PM
converting to mysql date format harryhood Absolute Beginners 1 08-21-2005 03:57 AM


All times are GMT. The time now is 03:25 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design