Welcome to Dream.In.Code
Become a PHP Expert!

Join 137,432 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,908 people online right now. Registration is fast and FREE... Join Now!




Date Format

 
Reply to this topicStart new topic

Date Format

jojodalde
11 Jan, 2008 - 10:12 PM
Post #1

New D.I.C Head
*

Joined: 3 Jan, 2008
Posts: 10

hey guys, im having a problem on how to format date in my database. and i really get stuck on it.

heres the date info:

the date currently outputs as YYYY-MM-DD
and I want it to output as "March 3, 2000"
Month being the first followed by day and the year.

i.e.

currently it displays: 2002-08-15
and I want: August 15, 2002

i have this code, and can u help me find whats wrong with this:

thanks!
CODE

$dbirth = '0000-00-00';
$dbirth = mktime("F j, Y", 0,0,0, $row['dbirth']);

Thanks!



User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Date Format
11 Jan, 2008 - 11:12 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,260



Thanked: 227 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
mktime doesn't take formatting characters. It takes hour, min, sec, month, day, year

So what you can do is use strtotime() to convert the date from the database into a timestamp which can then be used in date() (which takes the formatting characters) and make it the date.

Try this...

CODE

<?php
    $dtime = "2002-08-15";
    echo "Date is: " . date("F j, Y", strtotime($dtime));
?>


With this example you can see that you just plug in the date coming from the database into $dtime and using strtotime it will attempt to convert it to a legit timestamp which can then be formatted using date().

Enjoy!

"At DIC we be strtotime manipulating code ninjas!" decap.gif
User is offlineProfile CardPM
+Quote Post

jojodalde
RE: Date Format
13 Jan, 2008 - 05:46 PM
Post #3

New D.I.C Head
*

Joined: 3 Jan, 2008
Posts: 10

i have change my code and when i ran it, its like just nothins happen. biggrin.gif im confuse w/c part of my code where i put the strtotime function in printing the result and i just put it in line 13. is it possible to put it in line 56? by the way thanks for the idea!.. smile.gif

CODE

<?php

    $con = mysql_connect("localhost","pbclub","theclub");
    if (!$con)
      {
          die('Could not connect: ' . mysql_error());
      }

        mysql_select_db("pinkbox", $con);


        $dbirth = '0000-00-00';
        date("F j, Y", strtotime($dbirth));

        $query="SELECT * FROM club_members order by idno asc";
        $result=@mysql_query($query);
        $amount = mysql_num_rows($result);

        mysql_close($con);

mysql_connect("localhost","pbclub","theclub") or die ("cannot connect to database");
?>

<html>
<head></head>
<body bgcolor="pink">
<br><br>
          
<font face=arial narrow size=1 color=white><a href="welcomeadmin.php">ADMIN </a>  | 
                                           <a href="register.php">REGISTER </a>  | 
                                           <font face=arial narrow size=1 color=white><a href="logout.php">LOGOUT </a>
                                           </font><br><br>
<table width="900" cellpadding="0" cellspacing="0" align="center" border="1">
    <tr>
        <td colspan="7"align=center bgcolor="ea418f"><font face=arial size=3 color=fdcde7><b>PINKBOX CLUB MEMBERS</b></font></td>
    </tr>
    <tr>
        <td bgcolor=silver align=center style=border-left: 0px style=border-bottom: 0px><font face=arial size=2>BRANCH CODE</font></td>
        <td bgcolor=silver align=center style=border-left: 0px style=border-bottom: 0px><font face=arial size=2>IDNO</font></td>
        <td bgcolor=silver align=center style=border-left: 0px style=border-bottom: 0px><font face=arial size=2>NAME</font></td>
        <td bgcolor=silver align=center style=border-left: 0px style=border-bottom: 0px><font face=arial size=2>DATE OR BIRTH</font></td>
        <td bgcolor=silver align=center style=border-left: 0px style=border-bottom: 0px><font face=arial size=2>DATE REGISTERED</font></td>
        <td bgcolor=silver align=center style=border-left: 0px style=border-bottom: 0px><font face=arial size=2>CONTACT NUMBER</font></td>
        <td bgcolor=silver align=center style=border-left: 0px style=border-bottom: 0px><font face=arial size=2>EMAIL</font></td>
    </tr>

    <?php
    while($row=@mysql_fetch_array($result)) {

        print("

            <tr>
                <td align=center style=border-left: 0px style=border-bottom: 0px><font color=7a1243 face=arial size=2>$row[bcode]</font></td>
                <td align=center style=border-left: 0px style=border-bottom: 0px><font color=7a1243 face=arial size=2>$row[idno]</font></td>
                <td align=left style=border-left: 0px style=border-bottom: 0px><font color=7a1243 face=arial size=2>$row[name]</font></td>
                <td align=left style=border-left: 0px style=border-bottom: 0px><font color=7a1243 face=arial size=2>$row[dbirth]</font></td>
                <td align=left style=border-left: 0px style=border-bottom: 0px><font color=7a1243 face=arial size=2>$row[reg_date]</font></td>
                <td align=left style=border-left: 0px style=border-bottom: 0px><font color=7a1243 face=arial size=2>$row[contact_num]</font></td>
                <td align=left style=border-left: 0px style=border-bottom: 0px><font color=7a1243 face=arial size=2>$row[email]</font></td>
            </tr>

            ");
    }

    echo " <table border=1 width=900 align=center>
                <tr>
                    <td align=right bgcolor=silver><font face='arial' color='7a1243' size='1'> <b>".$amount." member(s)  </b></font></td>

                </tr>
            </table>

        ";
    ?>
</table>
</body>
</html>

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Date Format
13 Jan, 2008 - 08:55 PM
Post #4

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,260



Thanked: 227 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Don't set your $dbirth to "0000-00-00". Pull the date from the database and plug that into the setup I mentioned above. Don't forget to set the variable to the result of the date function. So you need to do $mynewdate = date("F j, Y", strtotime($dbirth));. Then you can use the variable $mynewdate anywhere you would use a variable... printing, calculations or whatever.

I hope that makes sense. smile.gif
User is offlineProfile CardPM
+Quote Post

jojodalde
RE: Date Format
17 Jan, 2008 - 05:59 PM
Post #5

New D.I.C Head
*

Joined: 3 Jan, 2008
Posts: 10

QUOTE(Martyr2 @ 13 Jan, 2008 - 09:55 PM) *

Don't set your $dbirth to "0000-00-00". Pull the date from the database and plug that into the setup I mentioned above. Don't forget to set the variable to the result of the date function. So you need to do $mynewdate = date("F j, Y", strtotime($dbirth));. Then you can use the variable $mynewdate anywhere you would use a variable... printing, calculations or whatever.

I hope that makes sense. smile.gif


ive used the code u gave 2 me but it doesnt make sense. it results an error Undefined index: mynewdate in c:\program files\easyphp1-8\www\pinkbox\club_members.php on line 69


and in the result i made it this way:

<td align=left style=border-left: 0px style=border-bottom: 0px><font color=7a1243 face=arial size=2>$row[mynewdate]</font></td>

by d way thanks for being patient.. smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/5/08 05:03AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month