473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

FormatDateTime in PHP

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!

Jan 5 '06 #1
10 3549
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
Jan 5 '06 #2
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
Jan 5 '06 #3

John K wrote:
All I want to do is convert a MySQL datetime field into a long date.
e.g. 2006-01-30 to January 1, 2006.


I recently asked a similar question. See if this thread helps:
http://groups.google.com/group/comp....00282f2d660cca

greg

Jan 5 '06 #4
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']; ?>

Jan 5 '06 #5
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
Jan 5 '06 #6
"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>
Jan 5 '06 #7
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);
?>

Jan 5 '06 #8
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
Jan 5 '06 #9
THAT DID IT, THANK YOU!!!! YES!

Jan 5 '06 #10
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

Jan 5 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jay | last post by:
I previously posted this question under Visual Basic newsgroup, but was advised to re-post here. I'm hoping someone can help me solve an issue I'm having with VB.Net and Access 2000. Here's...
6
by: Thomas Scheiderich | last post by:
I have the following page as test.aspx: *************************************************** <html> <head> <title>Hello and Welcome Page</title> </head> <body> <center> <% Dim CurrentDate As...
4
by: Sune | last post by:
Hi, Is there any way to define the default date/time format, instead of having to format every single time you print a date/time? Thanks -- Regards, Sune
12
by: DC Gringo | last post by:
How can I convert this pubLatest to a date with format "m/d/yyyy"? Dim pubLatest As New Date pubLatest = Me.SqlSelectCommand1.Parameters("@pubLatest").Value -- _____ DC G
5
by: John K | last post by:
I posted on this a week or so ago and found a resolution in that instance by using DATE_FORMAT in my sql string to display the format I was looking for. This time I need to format the date going...
2
by: fiefie.niles | last post by:
I set my computer Regional Setting (Control Panel - Regional and Language Options - Customize - Date) to dd/mm/yy. In my ASP page I do the following: FormatDateTime("1/20/07",2) and it...
1
by: nitinkeser | last post by:
how i convert date into specific format in asp? like in date format 'Jun 17, 2007' ?
1
by: janetopps | last post by:
This is an asp page which adds a template to a mysql database. it returns this error Microsoft VBScript runtime error '800a000d' Type mismatch: 'FormatDateTime' /temps.asp, line 111
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.