473,770 Members | 6,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to format at date field output

I have a field in a database called DateRcvd. At present, it outputs in my
report in the yyyy-mm-dd format. I would like it to display in the dd/mm/yy
format. What is the easiest way to accomplish this?
Jul 25 '06 #1
9 3451
Bob Sanderson wrote:
I have a field in a database called DateRcvd. At present, it outputs in my
report in the yyyy-mm-dd format. I would like it to display in the dd/mm/yy
format. What is the easiest way to accomplish this?
Depends on the database., But most have a function to format the
default date to however you want. Check your database documentation.

Otherwise you could reformat it in the php code - use substr() or a
regex to get the year, month and day, then display them like you wish.

Personally I prefer the database function.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jul 25 '06 #2
ronverdonk
4,258 Recognized Expert Specialist
[PHP]<?php
$d="2006-10-25";
echo date("d/m/y", strtotime($d));
?>[/PHP]
results in 25/10/06

Ronald :cool:
Jul 25 '06 #3
Bob Sanderson wrote:
I have a field in a database called DateRcvd. At present, it outputs
in my report in the yyyy-mm-dd format. I would like it to display in
the dd/mm/yy format. What is the easiest way to accomplish this?
You could reformat it using PHP:

echo date("d/m/y",strtotime($r ow["DateRcvd"]));

http://php.net/date
http://php.net/strtotime

--
Kim André Akerø
- ki******@NOSPAM betadome.com
(remove NOSPAM to contact me directly)
Jul 25 '06 #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bob Sanderson wrote:
I have a field in a database called DateRcvd. At present, it outputs in my
report in the yyyy-mm-dd format. I would like it to display in the
dd/mm/yy format. What is the easiest way to accomplish this?
Rely on the DB's date formatting functions. Something like:

select date_format( table.DateRcvd, '%y/%m/%d' ) as formatted_date from
table;

Please check your SQL DB manual for the exact syntax for those functions.
- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)

iD8DBQFExh5u3jc Q2mg3Pc8RAnR3AJ 9HyyXYCrNFijuaL PdffeRuYzNBagCc CcNW
Xn0pEQgp9bdzIal xackv3RE=
=EF4e
-----END PGP SIGNATURE-----
Jul 25 '06 #5
ronverdonk
4,258 Recognized Expert Specialist
Sorry I forgot, but when you want to use MySql to format it, just do:
Expand|Select|Wrap|Line Numbers
  1. select date , date_format(date, "%d/%m/%y") as date1 from table
then date1 contains your re-formatted date.

Ronald :cool:
Jul 25 '06 #6
On Tue, 25 Jul 2006 09:46:02 -0400, Jerry Stuckle wrote:
>I have a field in a database called DateRcvd. At present, it outputs in
my report in the yyyy-mm-dd format. I would like it to display in the
dd/mm/yy format. What is the easiest way to accomplish this?

Depends on the database., But most have a function to format the default
date to however you want. Check your database documentation.

Otherwise you could reformat it in the php code - use substr() or a regex
to get the year, month and day, then display them like you wish.

Personally I prefer the database function.
Personally I prefer Kim André Akerø's solution, it's easier to read and
programmer time is (in *most* of the work I do) worth more than CPU time.
However, Kim's method is by far the slowest. To do 10,000 iterations of
each version:

$ ./test.php
strtotime/date = 0.5179 seconds
ereg = 0.0885 seconds
preg = 0.0435 seconds
substr = 0.0282 seconds

However, as I rarely do more than one or two conversions like this per
page impression, and they are on fairly low traffic sites on powerful
boxes (max is about 5M page impressions per month) I'll stick to most
readable :-)

Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Jul 25 '06 #7
Andy Jeffries wrote:
>
Personally I prefer Kim André Akerø's solution, it's easier to read and
programmer time is (in *most* of the work I do) worth more than CPU time.
However, Kim's method is by far the slowest. To do 10,000 iterations of
each version:
Formatting within the PHP script might be easier to read, but databases
usually have extensive built-in calendaring capabilities. At least, that
is the case with Oracle (my favorite), SQL Server and PostgreSQL. All
the date rules are already built in, database "knows" what day will it
be on 7/4/2076, will it be a leap year and what day will Halloween fall
on this year. I find it wasteful to re-implement all those goodies in
PHP, just for purity.
--
Mladen Gogala
http://www.mgogala.com
Jul 25 '06 #8
*** Bob Sanderson escribió/wrote (Tue, 25 Jul 2006 12:49:17 GMT):
I have a field in a database called DateRcvd. At present, it outputs in my
report in the yyyy-mm-dd format. I would like it to display in the dd/mm/yy
format. What is the easiest way to accomplish this?
I particularly find it easier to handle dates as Unix timestamps. You don't
say what your DBMS is so I'll assume MySQL:

SELECT UNIX_TIMESTAMP( DateRcvd) FROM table

Once you read the value into a PHP variable, you can use almost date
function to format it, such as date() or strftime().

When you need to insert dates into MySQL:

INSERT INTO table (DateRcvd) VALUES (FROM_UNIXTIME( 1153851613))
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Jul 25 '06 #9
Andy Jeffries wrote:
On Tue, 25 Jul 2006 09:46:02 -0400, Jerry Stuckle wrote:
>>>I have a field in a database called DateRcvd. At present, it outputs in
my report in the yyyy-mm-dd format. I would like it to display in the
dd/mm/yy format. What is the easiest way to accomplish this?

Depends on the database., But most have a function to format the default
date to however you want. Check your database documentation.

Otherwise you could reformat it in the php code - use substr() or a regex
to get the year, month and day, then display them like you wish.

Personally I prefer the database function.


Personally I prefer Kim André Akerø's solution, it's easier to read and
programmer time is (in *most* of the work I do) worth more than CPU time.
However, Kim's method is by far the slowest. To do 10,000 iterations of
each version:

$ ./test.php
strtotime/date = 0.5179 seconds
ereg = 0.0885 seconds
preg = 0.0435 seconds
substr = 0.0282 seconds

However, as I rarely do more than one or two conversions like this per
page impression, and they are on fairly low traffic sites on powerful
boxes (max is about 5M page impressions per month) I'll stick to most
readable :-)

Cheers,
Andy

Andy,

Personally, I prefer to let the database handle it. It's generally
faster overall - the database probably had to convert it to yyyy-mm-dd
format in the first place. That way it can convert directly to the
desire format instead of going through two conversions.

And even if it doesn't have to convert it to yyyy-mm-dd, the compiled
code in the database is generally a lot more efficient than the PHP.

And that's the easiest to read!

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jul 25 '06 #10

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

Similar topics

1
4845
by: Laurence Neville | last post by:
This is regarding a change in the Short Date format under Hebrew Regional Settings, that has caused huge problems in our ASP web application. The change appears to have been introduced sometime before Windows 2000 Service Pack 4 and has remained through to Windows XP. I am looking for a solution that doesn't involve rewriting our application (much) and that allows all our users to keep using Hebrew Regional Settings. To summarize our...
5
816
by: Macca | last post by:
Hi, I have a table which has a date/time field. I am storing them as follows :- 01/01/2005 11:25 01/01/2005 19:44 02/01/2005 05:04
8
5892
by: bienwell | last post by:
Hi, I have a problem of displaying data bound by a datalist control. In my table, I have a field Start_date which has Short Date data type. I tried to update this field by Current Date. After that, I display End_Date on the DataList control. The output looks like 3/18/2005 12:00:00 AM . I'd like to format data for this field to be 3/18/2005. Please help me. Thanks in advance....
3
8707
by: pmarisole | last post by:
The following javascript code gives me the date validation that I need except after the correct date is entered into the field, it puts the date in the wrong format EXAMPLE: User enters 2/14/2006 and it shows in the field Feb 14 2006 after the onBlur I want it to leave the formatting of the date in the field as 2/14/2006 and not change the input to Feb 14 2006
3
7897
by: jaishu | last post by:
I am using ODBC with oracle tables.. My table has columns startdate and end date which are of type varchar(backend tables)..but when i display it in form it should display it as mm/dd/yyyy format, i tried setting format property as Short date but that doesnt work as my form is based on a query.and all the more my table stores the date as yyyymmdd -19990110, this is the way its stored in table (in varchar) so how do i do this? i also tried...
4
7540
by: dhutton | last post by:
Hello everyone, How would I go about changing the Date format so my query can read it. The below example does not work but if I were to have a table with YYYYMMDD the below query does work. The query doesnt like dashes or forward slashes when working with date fields in certain tables - How can I say in my query IF Date has dashes THEN change FROM 2007-08-01 to 20070801 or IF Date has forward slashes THEN change FROM 8/01/2007 to...
18
13045
by: Dirk Hagemann | last post by:
Hello, From a zone-file of a Microsoft Active Directory integrated DNS server I get the date/time of the dynamic update entries in a format, which is as far as I know the hours since january 1st 1901. For Example: the number 3566839 is 27.11.07 7:00. To calculate this in Excel I use this: ="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) (put 3566839 in field A1 and switch the format of the result-field to the corresponding...
10
6965
Nathan H
by: Nathan H | last post by:
I have several queries that make a new table for export. I need to find a way to format the date field in the exporting table before I output it. Here is what I am guessing at: Private Sub cmdAWBCSINGLE_Click() 'On Error GoTo RUNAPP_ERROR DoCmd.SetWarnings False DoCmd.OpenQuery "qryAWBCTEST" DoCmd.OpenQuery "qryAWBCSINGLE" Table!tblAWBC!.Format = "YYYYMMDD"
8
2955
by: yashiro | last post by:
Hello i Have a database in SQLserver. I am using php to connect to it and to retrieve data from that database. I have a table with a column (DATATIME) where i do : $result = mssql_query("SELECT date FROM table1") or die(mssql_error());
0
9591
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10225
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10053
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10001
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.