473,765 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to format a date?

I'm retrieving some records from a database. One of the fields
contains a date/time. I would like to format it as I send it out to
the table in the displayed page.

Can some one please tell me how I can/should do that? Or possibly
point me to an on-line explanation?

Thanks

ps: if it makes any difference, the data is coming from a MS Access
MDB file which I'm reading in via ODBC.
Jan 14 '08 #1
9 2940
Martin wrote:
I'm retrieving some records from a database. One of the fields
contains a date/time. I would like to format it as I send it out to
the table in the displayed page.

Can some one please tell me how I can/should do that? Or possibly
point me to an on-line explanation?

Thanks

ps: if it makes any difference, the data is coming from a MS Access
MDB file which I'm reading in via ODBC.
Don't know much about Access but I think you can use some of its internal
functions to return the a formatted date (like datepart() if I remember
well). Maybe you could get more help in comp.databases. ms-access.

Anyway, if you manage to get the 'intact' value in PHP, you've many string
functions (check the man) for formatting, or you can use date() if it's a
UNIX timestamp (but I don't think it is).

-thib´
Jan 14 '08 #2
Martin wrote:
I'm retrieving some records from a database. One of the fields
contains a date/time. I would like to format it as I send it out to
the table in the displayed page.

Can some one please tell me how I can/should do that? Or possibly
point me to an on-line explanation?

Thanks

ps: if it makes any difference, the data is coming from a MS Access
MDB file which I'm reading in via ODBC.
It is a 6 step process:

Step 1) Point your browser at www.google.com
Step 2) In the search box type: php date formatting
Step 3) Click the button labelled "I'm Feeling Lucky"
Step 4) Read the manual page that you are presented with
Step 5) Think "Why did I bother posting this question to usenet when I could
have found the answer in an instant by doing steps 1-4"
Step 6) Vow to do the obvious and try to help myself in the fuure.
Jan 14 '08 #3
thib´ wrote:
or you can use
date() if it's a UNIX timestamp (but I don't think it is).
But you can use strtotime() to turn it into one.

Jan 14 '08 #4
Paul Lautman wrote:
thib´ wrote:
>or you can use
date() if it's a UNIX timestamp (but I don't think it is).
But you can use strtotime() to turn it into one.
Yep, but just be aware that this function only tries to parse "GNU date
input formats". MS may not follow these rules ^^'. Does it?
Jan 14 '08 #5
On Mon, 14 Jan 2008 23:34:38 -0000, "Paul Lautman"
<pa**********@b tinternet.comwr ote:
>Martin wrote:
>I'm retrieving some records from a database. One of the fields
contains a date/time. I would like to format it as I send it out to
the table in the displayed page.

Can some one please tell me how I can/should do that? Or possibly
point me to an on-line explanation?

Thanks

ps: if it makes any difference, the data is coming from a MS Access
MDB file which I'm reading in via ODBC.

It is a 6 step process:

Step 1) Point your browser at www.google.com
Step 2) In the search box type: php date formatting
Step 3) Click the button labelled "I'm Feeling Lucky"
Step 4) Read the manual page that you are presented with
Step 5) Think "Why did I bother posting this question to usenet when I could
have found the answer in an instant by doing steps 1-4"
Step 6) Vow to do the obvious and try to help myself in the fuure.
Thanks for the wise-ass answer Paul.

The fact of the matter is, I already spent an hour or so Googling and
experimenting with various things. In fact, I tried using the exact
page that you so politely pointed out. But I quickly found out that
that page actually explains how to format the system date value. As
I'm sure you'll notice, if you would bother to read my question, I'm
trying to format a date/time string that I'm retrieving from a
database.

I suggest that you re-word your step 5 to: Think "Why did I bother
posting this question to a usenet group where I get smart-ass answers
that don't do any good".


Jan 15 '08 #6
Martin wrote:
On Mon, 14 Jan 2008 23:34:38 -0000, "Paul Lautman"
<pa**********@b tinternet.comwr ote:
>Martin wrote:
>>I'm retrieving some records from a database. One of the fields
contains a date/time. I would like to format it as I send it out to
the table in the displayed page.

Can some one please tell me how I can/should do that? Or possibly
point me to an on-line explanation?

Thanks

ps: if it makes any difference, the data is coming from a MS Access
MDB file which I'm reading in via ODBC.
It is a 6 step process:

Step 1) Point your browser at www.google.com
Step 2) In the search box type: php date formatting
Step 3) Click the button labelled "I'm Feeling Lucky"
Step 4) Read the manual page that you are presented with
Step 5) Think "Why did I bother posting this question to usenet when I could
have found the answer in an instant by doing steps 1-4"
Step 6) Vow to do the obvious and try to help myself in the fuure.

Thanks for the wise-ass answer Paul.

The fact of the matter is, I already spent an hour or so Googling and
experimenting with various things. In fact, I tried using the exact
page that you so politely pointed out. But I quickly found out that
that page actually explains how to format the system date value. As
I'm sure you'll notice, if you would bother to read my question, I'm
trying to format a date/time string that I'm retrieving from a
database.

I suggest that you re-word your step 5 to: Think "Why did I bother
posting this question to a usenet group where I get smart-ass answers
that don't do any good".

Well, the fact that many users come here without even having opened the man'
might be bothering, you should consider that. Of course I agree that we're
also here to redirect people to what they need if the request is something
widely assumed as 'basic'; many people would just say "Google that!" whereas
the personal glossary of the OP simply needs one or two little more entries.

In your case, I guess you aren't actually searching for date formatting, but
string formatting.

http://php.net/manual/en/ref.strings.php

You obviously don't need more than these native functions to do what you
want to. If your time is really running out, I suggest you start playing
with substr().

If you feel like you need further reading, you might be interested in
Regular Expressions.

http://www.regular-expressions.info/
http://php.net/manual/en/ref.pcre.php

Despite all of that, you can also convert your date to a UNIX timestamp,
using string functions as well as mktime(), or, as Paul pointed out, with
strtotime() if you're confident with the source format. You'll then have no
problem to re-format the timestamp with date().

You could have put a hand on these functions by reading a little further the
function references of "Date and Time" you should have found by following
Paul's "directives ". Yep, I felt lucky, and he was right.

http://php.net/manual/en/ref.datetime.php
"Google" vs "Direct-Help" is an everlasting debate.
No kittens are ate anyway, so keep your cool.

-thib´
Jan 15 '08 #7
On Tue, 15 Jan 2008 02:37:49 +0100, thib´ <th***@coralsna ke-team.com>
wrote:
>Martin wrote:
>On Mon, 14 Jan 2008 23:34:38 -0000, "Paul Lautman"
<pa**********@ btinternet.comw rote:
>>Martin wrote:
I'm retrieving some records from a database. One of the fields
contains a date/time. I would like to format it as I send it out to
the table in the displayed page.

Can some one please tell me how I can/should do that? Or possibly
point me to an on-line explanation?

Thanks

ps: if it makes any difference, the data is coming from a MS Access
MDB file which I'm reading in via ODBC.
It is a 6 step process:

Step 1) Point your browser at www.google.com
Step 2) In the search box type: php date formatting
Step 3) Click the button labelled "I'm Feeling Lucky"
Step 4) Read the manual page that you are presented with
Step 5) Think "Why did I bother posting this question to usenet when I could
have found the answer in an instant by doing steps 1-4"
Step 6) Vow to do the obvious and try to help myself in the fuure.

Thanks for the wise-ass answer Paul.

The fact of the matter is, I already spent an hour or so Googling and
experimentin g with various things. In fact, I tried using the exact
page that you so politely pointed out. But I quickly found out that
that page actually explains how to format the system date value. As
I'm sure you'll notice, if you would bother to read my question, I'm
trying to format a date/time string that I'm retrieving from a
database.

I suggest that you re-word your step 5 to: Think "Why did I bother
posting this question to a usenet group where I get smart-ass answers
that don't do any good".


Well, the fact that many users come here without even having opened the man'
might be bothering, you should consider that. Of course I agree that we're
also here to redirect people to what they need if the request is something
widely assumed as 'basic'; many people would just say "Google that!" whereas
the personal glossary of the OP simply needs one or two little more entries.

In your case, I guess you aren't actually searching for date formatting, but
string formatting.

http://php.net/manual/en/ref.strings.php

You obviously don't need more than these native functions to do what you
want to. If your time is really running out, I suggest you start playing
with substr().

If you feel like you need further reading, you might be interested in
Regular Expressions.

http://www.regular-expressions.info/
http://php.net/manual/en/ref.pcre.php

Despite all of that, you can also convert your date to a UNIX timestamp,
using string functions as well as mktime(), or, as Paul pointed out, with
strtotime() if you're confident with the source format. You'll then have no
problem to re-format the timestamp with date().

You could have put a hand on these functions by reading a little further the
function references of "Date and Time" you should have found by following
Paul's "directives ". Yep, I felt lucky, and he was right.

http://php.net/manual/en/ref.datetime.php
"Google" vs "Direct-Help" is an everlasting debate.
No kittens are ate anyway, so keep your cool.

-thib´
Thanks, thib'

Here's what I've ended up with:

$FTS = date("m/d/y h:i:s A",strtotime(od bc_result($rs," Date")));

I initially had played around with the date function but couldn't get
it to work with whatever format the data field is using. I then had
tried the strtotime function but didn't understand what it was
generating. All of this was before I posted my question.

Based on your initial response (and, as you've reiterated now),
combining the two gives me what I was looking for.

Thanks again.
Jan 15 '08 #8

"Martin" <ma**********@c omcast.netschre ef in bericht
news:cb******** *************** *********@4ax.c om...
On Mon, 14 Jan 2008 23:34:38 -0000, "Paul Lautman"
<pa**********@b tinternet.comwr ote:
>>Martin wrote:
>>I'm retrieving some records from a database. One of the fields
contains a date/time. I would like to format it as I send it out to
the table in the displayed page.

Can some one please tell me how I can/should do that? Or possibly
point me to an on-line explanation?

Thanks

ps: if it makes any difference, the data is coming from a MS Access
MDB file which I'm reading in via ODBC.

It is a 6 step process:

Step 1) Point your browser at www.google.com
Step 2) In the search box type: php date formatting
Step 3) Click the button labelled "I'm Feeling Lucky"
Step 4) Read the manual page that you are presented with
Step 5) Think "Why did I bother posting this question to usenet when I
could
have found the answer in an instant by doing steps 1-4"
Step 6) Vow to do the obvious and try to help myself in the fuure.

Thanks for the wise-ass answer Paul.

The fact of the matter is, I already spent an hour or so Googling and
experimenting with various things. In fact, I tried using the exact
page that you so politely pointed out. But I quickly found out that
that page actually explains how to format the system date value. As
I'm sure you'll notice, if you would bother to read my question, I'm
trying to format a date/time string that I'm retrieving from a
database.

I suggest that you re-word your step 5 to: Think "Why did I bother
posting this question to a usenet group where I get smart-ass answers
that don't do any good".


This page where you will end after step 4 says:
string date ( string $format [, int $timestamp ] )

so, if you use the correct timestamp you get out of your database.....

reading on, i reach example 1,
> // prints something like: 2000-07-01T00:00:00+00: 00
echo date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000));
This will convert the first day of the seventh mont in the yesr 2000 a
date........

so your suggestion indicates that you did NOT follow step 4 correctly? [ the
READ part ;) ]
Jan 15 '08 #9
On 14 Jan, 23:59, Martin <martinval...@c omcast.netwrote :
On Mon, 14 Jan 2008 23:34:38 -0000, "Paul Lautman"

<paul.laut...@b tinternet.comwr ote:
Martin wrote:
I'm retrieving some records from a database. One of the fields
contains a date/time. I would like to format it as I send it out to
the table in the displayed page.
Can some one please tell me how I can/should do that? Or possibly
point me to an on-line explanation?
Thanks
ps: if it makes any difference, the data is coming from a MS Access
MDB file which I'm reading in via ODBC.
It is a 6 step process:
Step 1) Point your browser atwww.google.co m
Step 2) In the search box type: php date formatting
Step 3) Click the button labelled "I'm Feeling Lucky"
Step 4) Read the manual page that you are presented with
Step 5) Think "Why did I bother posting this question to usenet when I could
have found the answer in an instant by doing steps 1-4"
Step 6) Vow to do the obvious and try to help myself in the fuure.

Thanks for the wise-ass answer Paul.

The fact of the matter is, I already spent an hour or so Googling and
experimenting with various things. In fact, I tried using the exact
page that you so politely pointed out. But I quickly found out that
that page actually explains how to format the system date value. As
I'm sure you'll notice, if you would bother to read my question, I'm
trying to format a date/time string that I'm retrieving from a
database.

I suggest that you re-word your step 5 to: Think "Why did I bother
posting this question to a usenet group where I get smart-ass answers
that don't do any good".
I suggest you practice reading. The date function takes a second
optional argument of a date value. I quote from the very top of teh
page:
"Returns a string formatted according to the given format string using
the given integer timestamp or the current time if no timestamp is
given. In other words, timestamp is optional and defaults to the value
of time()."

So you quickly didn't find out what the page said, because you didn't
even bother to read it properly.
Jan 15 '08 #10

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

Similar topics

1
60934
by: jt | last post by:
I posted this yesterday, but I am not seeing this out yet: I am having problems with updating a date field in a certain format. The data is stored in an Oracle database. The date is automatically displayed in format, "mm/dd/yyyy" on the ASP page, but it is accepted only in another format, "dd/mon/yy". I want to make it consistent. How can I force it to accept the date in format "mm/dd/yyyy"? The second option would be to force it to...
15
43016
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to mediate between webapps and arbitrary database backends using JDBC. I am very unwilling indeed to write special-case code for particular databases. Our code has worked satisfactorily with many databases, including many instances MS SQLServer 2000...
2
5065
by: amith | last post by:
hi I have written javascript for comparing two dates in US format and finding out whether the start date is greater than the end date and vice versa. In this attempt i have instantiated the date object with the date string which the user inputs from a pop up calendar. somewhat like this..........
10
1896
by: Jack | last post by:
Hi, I cannot get the date format correctly in dynamic sql statement, after trying various ways of handling it. I need some help with the date format in the following dynamic sql statement. Any help is appreciated in advance. While running the asp page, I still get an error as Error Type: Microsoft VBScript runtime (0x800A000D) Type mismatch: 'Format' DYNAMIC SQL STATEMENT:
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
13
3302
by: Roy | last post by:
Hi all, I'm creating a project that should always use this date format when displays the dates or create dates. The back end database is a SQL Server and I like to know what is the logical way to configure server, sql server or program so it always deals with date as mm/dd/yyyy format. Thanks in advance. Roy
20
35617
by: andreas | last post by:
When I copy a vb.net project using date formats from one PC with a windows date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I get errors. How can I change for a while in the project the date format in vb.code ( not in Windows) and how can I find out which date format the PC Windows is using. Thanks for any response
7
6821
by: Richiep | last post by:
I am trying to get a UK format date of dd/mm/yyyy. Why does the following subroutine not return a valid date in a web form? The date returned is #12:00:00 AM# but the date I entered into the text box was 24/06/2006. The other solution I have tried is given by the following two lines that do not compile because a value of date type cannot be converted to datetime:
16
11910
by: Mik | last post by:
I apologise if this post seems a little basic, but I am a newbie and have NO access knowledge. I have downloaded the Accounts Ledger from the Microsoft Website. It allows the user to review a report of transactions between a Start & End date. The Tables and forms i believe are UK format "dd/mm/yyyy", However, when I click on "Review Reports" and enter the date as UK "dd/mm/yyyy", it returns nothing.
10
5821
by: ARC | last post by:
Hello all, General question for back-end database that has numerous date fields where the database will be used in regions that put the month first, and regions that do not. Should I save a date format in the table design, such as: mm/dd/yyyy? What I've done for years is to store the date format in date fields, then on the forms, based on their region, I would set the date formats on form_load
0
10007
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
9957
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
8832
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...
0
6649
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();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
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.