View Full Version : timestamp in my db from yyyy/mm/dd to dd/mm/yyyy
runnerjp
04-10-2008, 03:11 PM
hey guys...is it possible to chnage the timestamp in my db from yyyy/mm/dd to dd/mm/yyyy as in echoing it
kbluhm
04-10-2008, 03:20 PM
There are numerous ways to accomplish this... here are a couple:
$date = $row['date']; // yyyy/mm/dd from a MySQL result
// solution #1
$date = strtotime( $date );
$date = date( 'd/m/Y', $date );
// solution #2
list( $year, $month, $day ) = explode( '/', $date );
$date = sprintf( '%s/%s/%s', $day, $month, $year );
You could also do the conversion in the query using MySQL's DATE_FORMAT (http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format)() function (assuming you are using MySQL):
SELECT DATE_FORMAT( `date`, '%d/%m/%Y' ) AS `formattedDate` FROM `table`
runnerjp
04-10-2008, 03:34 PM
ah ok i used this to record my time $timedate = time();
and then this to output it ".$sent_on."</i> - Date: ".date("D m Y",$datetime)."
but my output is Date: Thu 04 2008 how can i make it so its 10-04-2008
kbluhm
04-10-2008, 03:36 PM
That is not at all what you asked in your initial question. Wow, it's not even close aside from the fact that you're still talking about date manipulation.
You'll simply need to change the format of the first parameter in the date() function.
http://www.php.net/date
runnerjp
04-10-2008, 03:39 PM
hey ok iv been tinkering and stuff and need a little more help
ah ok i used this to record my time $timedate = time();
and then this to output it ".$sent_on." - Date: ".date("D m Y",$datetime)."
but my output is Date: Thu 04 2008 how can i make it look like Apr 10th, 2008 at 10:20 AM GMT
i belive its sonmthing like so
$sent_on = date("M jS, Y \a\\t h:i A T", $post_date);
runnerjp
04-10-2008, 03:43 PM
humm im confused now lol how about i post my 2 scripts to give u guys a better picture lol
<?php
session_start();
require_once '../settings.php';
checkLogin ('1');
$qProfile = "SELECT * FROM sysmsg ORDER BY msg_id DESC";
$rsProfile = mysql_query($qProfile);
while($row = mysql_fetch_array($rsProfile)){
$msg_id = $row['msg_id'];
$sent_on = $row['sent_on'];
$sent_by = $row['sent_by'];
$subject = $row['subject'];
$message = $row['message'];
$datetime = $row['sent_date'];
echo("<p>Subject: <b>".$subject."</b></p><p><i>Posted by:".$sent_by." on ".$sent_on."</i> - Date: ".date("D m Y",$datetime)."</p>
<p>".$message."<br><br></p>");
}
mysql_close();
if($id == 1){
echo "<a href=\"http://www.runningprofiles.com/members/index.php?page=admin\">Admin Index</a>\n";
}
?>
<a href="../index.php">Back to index</a><br>
<br>
<?php
include("connect.php");
// $msg_id should not change - do not let the user change this, use the message id to find the message you are wanting to edit.
$msg_id = mysql_escape_string($_POST['msg_id']);
$sent_by = mysql_escape_string($_POST['sent_by']);
$subject = mysql_escape_string($_POST['subject']);
$message = mysql_escape_string($_POST['message']);
// This gives the unix timestamp of the current time down to the second.
$timedate = time();
// make sure $msg_id POSTED from the previous page is an id that you want to change. ALSO make sure `sent_date` field exists.
$update = "UPDATE `sysmsg`
SET
`sent_by`='$sent_by',
`subject`='$subject',
`message`='$message',
`sent_date`='$timedate'
WHERE `msg_id`='$msg_id'
";
$rsUpdate = mysql_query($update) or die("Mysql Query Error For:<br />".$update."<br /><br />MySQL Said: ".mysql_error());
if (mysql_affected_rows() >= 1)
{
echo "Update successful.";
}else{
echo "No rows were updated";
}
mysql_close();
?>
kbluhm
04-10-2008, 03:43 PM
hey ok iv been tinkering and stuff and need a little more help
ah ok i used this to record my time $timedate = time();
and then this to output it ".$sent_on." - Date: ".date("D m Y",$datetime)."
but my output is Date: Thu 04 2008 how can i make it look like Apr 10th, 2008 at 10:20 AM GMT
i belive its sonmthing like so
$sent_on = date("M jS, Y \a\\t h:i A T", $post_date);
What format are you looking for? That is the third one you've presented in three messages.
- F will give you April
- d will give you 10
- Y will give you 2008
...etc, it's all laid out for you in that link I gave you.
runnerjp
04-10-2008, 03:50 PM
ahhh ok i did it ty for ur time and help
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.