Page 1 of 1

makeDateTime and DoFormatCurrency php functions

Posted: Fri Jan 08, 2010 4:13 pm
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?

Re: makeDateTime and DoFormatCurrency php functions

Posted: Fri Jan 08, 2010 6:06 pm
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.

Re: makeDateTime and DoFormatCurrency php functions

Posted: Sat Jan 09, 2010 10:10 am
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?

Re: makeDateTime and DoFormatCurrency php functions

Posted: Sat Jan 09, 2010 11:27 am
by AbraCadaver
Count your parentheses. If you have two opening ( then you need two closing ).

Re: makeDateTime and DoFormatCurrency php functions

Posted: Sat Jan 09, 2010 11:49 am
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.