makeDateTime and DoFormatCurrency php functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
socrates_777
Forum Newbie
Posts: 3
Joined: Fri Jan 08, 2010 4:11 pm

makeDateTime and DoFormatCurrency php functions

Post by socrates_777 »

Let me start by saying that I am very new to PHP and DBs. I am taking a lynda course called "Dreamweaver CS4 Dynamic Development". I have been doing static websites and wanted to take it a step further. Here is my problem.

Following along with the course we are creating a form that will display existing data in form controls. Early in the course they told me to go to adobe exchange and download the "FX_PHP_DateTFormats.mxp" and "MX744392_PHPServerFormats.mxp" ext for php functions in Dreamweaver CS4. I did and installed them correctly.

Now we are at a part where we are formatting output from the db. The initial code looks like this:

"<input name="pubdate" type="text" id="pubdate" value="<?php echo $row_rsTitle['pubdate']; ?>" />"

and displays an output that looks like this:

"2003-01-05 00:00:00"

It asks me to go through the menus to select and create this code under the menu label 0f "Date - 01/05/2004":

"<input name="pubdate" type="text" id="pubdate" value="<?php echo makeDateTime($row_rsTitle['pubdate'], 'm/d/Y'); ?>" />"

Now it's suppose to output the 01/05/2004 format but instead I get the following error:

"Fatal error: Call to undefined function makeDateTime() in C:\wamp\www\dwwithphp\titleupdateform.php on line 127"

Line 127 is this line:

"<input name="pubdate" type="text" id="pubdate" value="<?php echo makeDateTime($row_rsTitle['pubdate'], 'm/d/Y'); ?>" />"

Now I have been googling this for hours. I have found some people that say that the makeDateTime php function doesn't exist and others that show how to use it but not with a variable being output from the db. I have tried researching date function with php but none of the sites that i found show how to couple it with a db output.

I am getting a similar error with DoFormatCurrency for my price field.

Any idea?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: makeDateTime and DoFormatCurrency php functions

Post by pickle »

Ya, makeDateTime() doesn't exist in PHP. You want date() and strtotime().

It looks like the string you've got is a MySQL DATETIME stamp. If you run that through strtotime(), you'll get a UNIX timestamp. You can then use date() to output the date in the format you expect. Something like:

Code: Select all

echo date('d/m/Y',strtotime($row_rsTitle['pubdate']);
Or you can modify your query & put

Code: Select all

UNIX_TIMESTAMP(`whatever column your date is coming from`) AS `new column name`
in your query.

If you're wanting to learn PHP, I strongly suggest not using shortcuts like what Dreamweaver provides. You need to learn how to do it the hard way before the easy way makes sense.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
socrates_777
Forum Newbie
Posts: 3
Joined: Fri Jan 08, 2010 4:11 pm

Re: makeDateTime and DoFormatCurrency php functions

Post by socrates_777 »

Well I tried the first one:

"<input name="pubdate" type="text" id="pubdate" value="<?php echo date('d/m/Y',strtotime($row_rsTitle['pubdate']); ?>" />"

and got the following parse result:

"Parse error: parse error in C:\wamp\www\dwwithphp\titleupdateform.php on line 127"

I have researched parse errors and have been told that they are usually from misplaced semicolons or misdefined table info. I have double checked the references and the semicolons look correct to me.

What do you think?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: makeDateTime and DoFormatCurrency php functions

Post by AbraCadaver »

Count your parentheses. If you have two opening ( then you need two closing ).
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
socrates_777
Forum Newbie
Posts: 3
Joined: Fri Jan 08, 2010 4:11 pm

Re: makeDateTime and DoFormatCurrency php functions

Post by socrates_777 »

WOW!!! Thank you thank you thank you. Your solutions worked! Now I can continue with the lessons.

I am assuming that I can use a similar solution with DoFormatCurrency and strtotime.
Post Reply