Jump to content


changing display of date


10 replies to this topic

#1 HEki_

    Young Padawan

  • Members
  • Pip
  • 165 posts

Posted 18 May 2007 - 11:59 PM

Hi,

i am using simple script to get date

<?php 
$t=getdate();
$st_datum=date('Y-m-d',$t[0]);
?>

and than i write this date into the database. When i inserted a new field in database table "st_datum" and select "date" as datatype it automaticly gave me formation like "Y-m-d". So the the date get stored like 2007-5-19.

Now i want to display this info from table, however i want it to display like 19-5-2007.

So i went and change in the code 'Y-m-d' to 'd-m-Y' but than the date info wasnt stored in data base.

How do i change the Y-m-d order in database? Or is there any other option?

Best regards,
Heki

#2 magiceye

    Young Padawan

  • Members
  • Pip
  • 11 posts

Posted 19 May 2007 - 12:09 AM

You have to insert the time stamp to the database like so:
<?php

	 mysql_query (   "insert into tblname (time) values ('" . time (   ) . "');"   );

?>

and then you can use it later:
<?php

	 $d = date (   "d-m-Y", $tblname_time   );

?>

Edited by magiceye, 19 May 2007 - 12:21 AM.


#3 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 19 May 2007 - 12:13 AM

http://www.php.net/date


There's a nice table that tells you what each letter does and examples on how to use it. ^_^

#4 HEki_

    Young Padawan

  • Members
  • Pip
  • 165 posts

Posted 19 May 2007 - 01:03 AM

Thanks guys!

i have 1 more problem.

  echo "<tr>";
  echo "<td>" . $row['st_datum'] . "</td>";
  echo "<td>" . $row['st_url'] . "</td>";
  echo "</tr>";

i am trying to show the . $row['st_url'] . as a href ... i just cant figure this simple thing out?
tried everything and i cant get it to show as a href ^_^

#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 19 May 2007 - 01:46 AM

You have to wrap in in an anchor tag for it to show as a link... Before you try learning php, make sure you know basic html, it will help smooth out the learning curve.

Edited by rc69, 19 May 2007 - 01:46 AM.


#6 HEki_

    Young Padawan

  • Members
  • Pip
  • 165 posts

Posted 19 May 2007 - 02:02 AM

View Postrc69, on May 19 2007, 06:46 AM, said:

You have to wrap in in an anchor tag for it to show as a link... Before you try learning php, make sure you know basic html, it will help smooth out the learning curve.

i know the basics of html ... php is giving me truble! couse i am new to that!

echo "<td><a href=\"$row['st_url']\">$row['st_url']<a></td>";
echo "<td>" . <a href=\"$row['st_url']\">$row['st_url']<a> . "</td>";
echo "<td>""<a href=\"$row['st_url']\">$row['st_url']<a>""</td>";
.
.
.

hundrets other tries, nothing works ^_^

#7 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 19 May 2007 - 04:39 AM

echo '<td><a href="'.$row['st_url'].'">'.$row['st_url'].'</a></td>';

With strings and html within them, I prefer to use the single quotes, that way there is no need to backslash any of the html. Also when working with php within a string, i tend to break out of the string and concatonate the php in using a ., and then adding the rest of the string back on.

The first example should work fine, but you didn't close the a tag: you did <a>, to end the link tag you need to do </a>.

Matt

Edited by Mr. Matt, 19 May 2007 - 04:40 AM.


#8 HEki_

    Young Padawan

  • Members
  • Pip
  • 165 posts

Posted 19 May 2007 - 05:43 AM

thx a lot man.

ill just use ur example, couse in previous post i was typing from head ... in actual file, i have closed <a></a> and it still doesnt work ...

yours works fine ^_^

thx

#9 HEki_

    Young Padawan

  • Members
  • Pip
  • 165 posts

Posted 19 May 2007 - 06:22 AM

just out of curiosity,
how would this with double quotes work?

#10 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 19 May 2007 - 06:27 AM

Well baring that in mind, your second example:

echo "<td>" . <a href=\"$row['st_url']\">$row['st_url']<a> . "</td>";

Wouldn't work because the A would need to be quoted, so if i changed it to this it should work:

echo "<td>" . "<a href=\"$row['st_url']\">$row['st_url']<a>" . "</td>";

Your third example:

echo "<td>""<a href=\"$row['st_url']\">$row['st_url']<a>""</td>";

Did the oposite to the 2nd one, you had the strings, but you didn't concatonate them together, so this should work:

echo "<td>"."<a href=\"$row['st_url']\">$row['st_url']<a>"."</td>";

And your first example would have worked if you had closed the a tag at the end.

EDIT

with your last post i just saw, with double quotes it would just be:

echo "<td><a href=\"".$row['st_url']."\">".$row['st_url']."</a></td>";

Hope that helps you a bit,

Matt

Edited by Mr. Matt, 19 May 2007 - 06:29 AM.


#11 HEki_

    Young Padawan

  • Members
  • Pip
  • 165 posts

Posted 19 May 2007 - 11:52 AM

wao
thx for this explanation!
it clears a few things :P

best regards,
heki





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users