473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Dreamweaver help: using PHP/MySQL formatting date

hello,

On a dynamic html page I have a table with a date column

Expand|Select|Wrap|Line Numbers
  1. <td><?php echo $row_resultado_viajes['fecha']; ?>&nbsp; </td>
I want the date to be displayed in other format so I am using the date function

Expand|Select|Wrap|Line Numbers
  1. <td><?php echo date("j-m-Y",$row_resultado_viajes['fecha']); ?>&nbsp; </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,
Mar 29 '08 #1
12 4220
ronverdonk
4,258 Expert 4TB
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
Mar 29 '08 #2
ronverdonk
4,258 Expert 4TB
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
Mar 29 '08 #3
aktar
105 100+
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
Mar 29 '08 #4
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 :)
Mar 29 '08 #5
ronverdonk
4,258 Expert 4TB
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
Mar 29 '08 #6
ronverdonk
4,258 Expert 4TB
Thanks ronverdonk! it works fine now :)
You are welcome. See you next time.

Ronald
Mar 29 '08 #7
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.
Mar 29 '08 #8
ronverdonk
4,258 Expert 4TB
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:
Expand|Select|Wrap|Line Numbers
  1. select date_format(fecha, "%d-%m-%Y") as fecha;
Ronald
Mar 29 '08 #9
The correct MySQL format for this query would be in your case:
Expand|Select|Wrap|Line Numbers
  1. 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
Mar 30 '08 #10
ronverdonk
4,258 Expert 4TB
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']; ?>&nbsp; </td>[/php]Ronald
Mar 30 '08 #11
aktar
105 100+
rodrigo never said that this field comes from MySQL. Could be Oracle, DB/2 or even Access.
Ronald
Read the thread title old man
Apr 1 '08 #12
Markus
6,050 Expert 4TB
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.
Apr 1 '08 #13

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

Similar topics

6
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...
0
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:...
7
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...
4
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...
31
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...
0
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...
6
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...
1
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...
7
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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...
0
BarryA
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.