I recently took a job doing PHP but come from an ASP background. I'm
trying to find a conversion equivalent for VBScript's "formatdatetime".
All I want to do is convert a MySQL datetime field into a long date.
e.g. 2006-01-30 to January 1, 2006.
PLEASE provide an example that I can use as a future benchmark so I can
understand the syntax better. I really need to learn PHP and I'm a
little freaked out right now.
Thanks! 10 3457
John K wrote: I recently took a job doing PHP but come from an ASP background. I'm trying to find a conversion equivalent for VBScript's "formatdatetime".
All I want to do is convert a MySQL datetime field into a long date. e.g. 2006-01-30 to January 1, 2006.
PLEASE provide an example that I can use as a future benchmark so I can
understand the syntax better. I really need to learn PHP and I'm a little freaked out right now.
Thanks!
2006-01-30 can be converted to "January 1, 2006" using
date("F j, Y",mktime(0,0,0,01,30,2006));
Or, you can accomplish the same task with variables stuck into the mktime
function:
date("F j, Y",mktime($hour,$minute,$second,$month,$day,$year) );
Kevin http://www.php.net/manual/en/ is a great place to start learning PHP.
Also, they have a function search on that page which allows you to
search for functions... The search input field has an auto-complete
feature to help you find the function you wish to locate.
Good Luck at your new job!
Scot
John K wrote: I recently took a job doing PHP but come from an ASP background. I'm trying to find a conversion equivalent for VBScript's "formatdatetime".
All I want to do is convert a MySQL datetime field into a long date. e.g. 2006-01-30 to January 1, 2006.
PLEASE provide an example that I can use as a future benchmark so I can
understand the syntax better. I really need to learn PHP and I'm a little freaked out right now.
Thanks!
--
Scot McConnaughay
This is how I'm trying to do this at the moment, I should have included
this first, sorry.
<?php require_once('Connections/hthConnect.php'); ?>
<?php
mysql_select_db($database_hthConnect, $hthConnect);
$query_gigRecall = "SELECT tbl_gigs.fld_gig_Date,
tbl_gigs.fld_gig_Time, tbl_gigs.fld_gig_Title, tbl_gigs.fld_gig_Place
FROM tbl_gigs WHERE tbl_gigs.fld_gig_Date >= CURDATE()";
$gigRecall = mysql_query($query_gigRecall, $hthConnect) or
die(mysql_error());
$row_gigRecall = mysql_fetch_assoc($gigRecall);
$totalRows_gigRecall = mysql_num_rows($gigRecall);
?>
<span class="midYellowCaps"><?php echo $row_gigRecall['fld_gig_Title'];
?></span><br>
HERE WHERE I'M TRYING TO FORMAT THE DATE BELOW
<?php echo $row_gigRecall['fld_gig_Date']; ?> at <?php echo
$row_gigRecall['fld_gig_Time']; ?>
John K wrote: This is how I'm trying to do this at the moment, I should have included this first, sorry.
<?php require_once('Connections/hthConnect.php'); ?> <?php mysql_select_db($database_hthConnect, $hthConnect); $query_gigRecall = "SELECT tbl_gigs.fld_gig_Date, tbl_gigs.fld_gig_Time, tbl_gigs.fld_gig_Title, tbl_gigs.fld_gig_Place FROM tbl_gigs WHERE tbl_gigs.fld_gig_Date >= CURDATE()"; $gigRecall = mysql_query($query_gigRecall, $hthConnect) or die(mysql_error()); $row_gigRecall = mysql_fetch_assoc($gigRecall); $totalRows_gigRecall = mysql_num_rows($gigRecall); ?> <span class="midYellowCaps"><?php echo $row_gigRecall['fld_gig_Title']; ?></span><br> HERE WHERE I'M TRYING TO FORMAT THE DATE BELOW <?php echo $row_gigRecall['fld_gig_Date']; ?> at <?php echo $row_gigRecall['fld_gig_Time']; ?>
Why not just retrieve the date in that format with the query? http://dev.mysql.com/doc/refman/5.0/...functions.html
SELECT
DATE_FORMAT('%M %e, %Y',tbl_gigs.fld_gig_Date) as fld_gig_Date,
tbl_gigs.fld_gig_Time, tbl_gigs.fld_gig_Title, tbl_gigs.fld_gig_Place
FROM tbl_gigs WHERE tbl_gigs.fld_gig_Date >= CURDATE()
--
Justin Koivisto, ZCE - ju****@koivi.com http://koivi.com
"John K" <ki*****@yahoo.com> kirjoitti
viestissä:11**********************@f14g2000cwb.goo glegroups.com... I recently took a job doing PHP but come from an ASP background. I'm trying to find a conversion equivalent for VBScript's "formatdatetime".
All I want to do is convert a MySQL datetime field into a long date. e.g. 2006-01-30 to January 1, 2006.
$unixTimeStamp = strtotime('2006-01-30');
date('F d, Y', $unixTimeStamp);
Returns January 30, 2006
--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at <http://setiweb.ssl.berkeley.edu/>
Kimmo Laine <an*******************@gmail.com.NOSPAM.invalid>
I tried it didn't produce a result (the date that is). Time produced
result however.
This is what I put in. Did I do something wrong?
<?php
mysql_select_db($database_hthConnect, $hthConnect);
$query_gigRecall = "SELECT DATE_FORMAT('%M %e,
%Y',tbl_gigs.fld_gig_Date) as fld_gig_Date, tbl_gigs.fld_gig_Time,
tbl_gigs.fld_gig_Place FROM tbl_gigs";
$gigRecall = mysql_query($query_gigRecall, $hthConnect) or
die(mysql_error());
$row_gigRecall = mysql_fetch_assoc($gigRecall);
$totalRows_gigRecall = mysql_num_rows($gigRecall);
?>
John K wrote: I tried it didn't produce a result (the date that is). Time produced result however.
This is what I put in. Did I do something wrong?
<?php mysql_select_db($database_hthConnect, $hthConnect); $query_gigRecall = "SELECT DATE_FORMAT('%M %e, %Y',tbl_gigs.fld_gig_Date) as fld_gig_Date, tbl_gigs.fld_gig_Time, tbl_gigs.fld_gig_Place FROM tbl_gigs"; $gigRecall = mysql_query($query_gigRecall, $hthConnect) or die(mysql_error()); $row_gigRecall = mysql_fetch_assoc($gigRecall); $totalRows_gigRecall = mysql_num_rows($gigRecall); ?>
maybe it has to do with the name... try this instead:
DATE_FORMAT('%M %e, %Y',tbl_gigs.fld_gig_Date) as formatGigDate
and then:
<?php echo $row_gigRecall['formatGigDate']; ?>
--
Justin Koivisto, ZCE - ju****@koivi.com http://koivi.com
THAT DID IT, THANK YOU!!!! YES!
On Thu, 05 Jan 2006 06:50:25 -0800, John K wrote: I recently took a job doing PHP but come from an ASP background. I'm trying to find a conversion equivalent for VBScript's "formatdatetime".
All I want to do is convert a MySQL datetime field into a long date. e.g. 2006-01-30 to January 1, 2006.
PLEASE provide an example that I can use as a future benchmark so I can
understand the syntax better. I really need to learn PHP and I'm a little freaked out right now.
Thanks!
That's what PEAR Date is for. Here is the example you provided:
$ php /tmp/ttt.php
January 01, 2006
$ cat /tmp/ttt.php
<?php
require_once("Date.php");
$d=new Date("2006-01-30 00:00:00");
echo $d->format("%B %m, %Y"),"\n";
?>
-- http://www.mgogala.com This discussion thread is closed Replies have been disabled for this discussion. Similar topics
3 posts
views
Thread by Jay |
last post: by
|
6 posts
views
Thread by Thomas Scheiderich |
last post: by
|
4 posts
views
Thread by Sune |
last post: by
|
12 posts
views
Thread by DC Gringo |
last post: by
|
5 posts
views
Thread by John K |
last post: by
|
2 posts
views
Thread by fiefie.niles |
last post: by
| | | | | | | | | | | | |