hello,
On a dynamic html page I have a table with a date column - <td><?php echo $row_resultado_viajes['fecha']; ?> </td>
I want the date to be displayed in other format so I am using the date function - <td><?php echo date("j-m-Y",$row_resultado_viajes['fecha']); ?> </td>
but I am getting a strange date echoed (31-12-1969). The day seems to be correct but the month and year are far from being right.
thanks,
12 4220
What exact format (type and content) is the variable $row_resultado_viajes['fecha'].
As you know, date() works with a format description (1st parm) and the time in integer (2nd parm).
Ronald
When that field is a database date field in MySQL DATE format (YYYY-MM-DD), then convert the database date field to integer and then reformat that to the desired output format, like[php]
echo date("j-m-Y", strtotime($row_resultado_viajes['fecha'));[/php]Ronald
When that field is a database date field in MySQL DATE format (YYYY-MM-DD), then convert the database date field to integer and then reformat that to the desired output format, like[php]
echo date("j-m-Y", strtotime($row_resultado_viajes['fecha'));[/php]Ronald
Thanks ronverdonk! it works fine now :)
You could also format the date in your mysql query
see the following page: http://dev.mysql.com/doc/refman/5.0/...on_date-format
rodrigo never said that this field comes from MySQL. Could be Oracle, DB/2 or even Access.
And, by the way, this is the PHP forum, not the MySQL forum.
Ronald
Thanks ronverdonk! it works fine now :)
You are welcome. See you next time.
Ronald
You could also format the date in your mysql query
see the following page: http://dev.mysql.com/doc/refman/5.0/...on_date-format
Yes, indeed I tried a lot of time to do it but I am a newbie in this and could not code it correctly in my dreamweaver code edit I now the code should be something like this (for example)
SELECT DATE_FORMAT(fecha, '%W %M %Y');
but don't know how to open a mysql code in dreamweaver code editor for this pourpuse.
Yes, indeed I tried a lot of time to do it but I am a newbie in this and could not code it correctly in my dreamweaver code edit I now the code should be something like this (for example)
SELECT DATE_FORMAT(fecha, '%W %M %Y');
but don't know how to open a mysql code in dreamweaver code editor for this pourpuse.
The correct MySQL format for this query would be in your case: - select date_format(fecha, "%d-%m-%Y") as fecha;
Ronald
The correct MySQL format for this query would be in your case: - select date_format(fecha, "%d-%m-%Y") as fecha;
Ronald
ok, but hoe should I insert that mysql statement into my page code? I tried with:
mysql>.........
mysql = ......
sql =.......
but now success.
thanks
Since I don't use Dreamweaver (it's much nicer to write your own code) I have no idea how MySQL fits in it. However, I can show you the PHP code that would be used to access the MySQL database.
How you do that in DW I have no idea, but I will change the thread title a bit and let's hope that some DW guru sees it and can help you further.
The PHP code would be someting like[php]// Make a MySQL Connection
$conn = mysql_connect("localhost", "userid", "password")
or die("Could not connect to the database server: ".mysql_error());
// select the database
mysql_select_db("db_name", $conn)
or die("Could not select the database: " . mysql_error());
// construct your SQL statement
$sql="SELECT DATE_FORMAT(fecha, "%d-%m-%Y") as fecha FROM table_name WHERE your_condition";
// execute the sql statement
$result=mysql_query($sql)
or die("SELECT error: ".mysql_error());
// no rows selected: exit with message
if (mysql_num_rows < 1)
die ("No rows selected");
// fetch the selected row
$row_resultado_viajes = mysql_fetch_assoc($result);
// Here follows the code you showed at the start of the thread
?>
<td><?php echo $row_resultado_viajes['fecha']; ?> </td>[/php]Ronald
rodrigo never said that this field comes from MySQL. Could be Oracle, DB/2 or even Access.
Ronald
Read the thread title old man
Read the thread title old man
Not sure the 'old man' was necessary.
And i'm pretty sure the thread title has been changed from what it was originally.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: James Turner |
last post by:
I am trying to store formatted text (windows format) into a MySQL
database and then retrieve it. The field in the database is a
varchar. I cut and paste the test into a form field formatted, then...
|
by: Gregory |
last post by:
I am using OS X and Dreamweaver MX. I am trying to make a connection
to the MySQL Server from within Dreamweaver using the Applications
panel and clicking on the "+". A window opens asking for:...
|
by: Glen Eustace |
last post by:
This may have been better posted in the advocacy list but I am not a
subscriber.
We recently purchased Dreamweaver MX and I was a little surprised to
find that one of its pre-defined scripting...
|
by: Ian |
last post by:
Hi there,
Has anybody got any tips or recommendations for using Vs.Net and Dreamweaver
2004 together?
I like to use dreamweaver as the layout tool as for me it just seems a
little more...
|
by: Extremest |
last post by:
I have a loop that is set to run as long as the arraylist is > 0.
at the beginning of this loop I grab the first object and then
remove it. I then go into another loop that checks to see if there...
|
by: gunimpi |
last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431
********************************************************
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
wanted...
|
by: Brandon |
last post by:
I'm using PHP with MySQL 4.x and was having trouble converting a
datetime from MySQL into a formatted string until I ran across this
solution that converts a YYYY-MM-DD HH:MM:SS string into a...
|
by: iancarr00 |
last post by:
Ok, So far I have been pulling my hair out!
I can't get dreamweaver mx8 (on mac osx) to access my database, which is sat on a streamline.net shared windows server. I have acsess to my database...
|
by: gubbachchi |
last post by:
Hi all,
In my application I need to display the data fetched from mysql database after the user selects date from javascript calender. I have written the code in which after the user selects the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |