How to format a date?

How to format a date?

am 15.01.2008 00:28:02 von martin

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.

Re: How to format a date?

am 15.01.2008 00:33:34 von thyb0

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´

Re: How to format a date?

am 15.01.2008 00:34:38 von Paul Lautman

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.

Re: How to format a date?

am 15.01.2008 00:38:36 von Paul Lautman

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.

Re: How to format a date?

am 15.01.2008 00:53:02 von thyb0

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?

Re: How to format a date?

am 15.01.2008 00:59:20 von martin

On Mon, 14 Jan 2008 23:34:38 -0000, "Paul Lautman"
wrote:

>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".

Re: How to format a date?

am 15.01.2008 02:37:49 von thyb0

Martin wrote:
> On Mon, 14 Jan 2008 23:34:38 -0000, "Paul Lautman"
> wrote:
>
>> 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´

Re: How to format a date?

am 15.01.2008 03:48:01 von martin

On Tue, 15 Jan 2008 02:37:49 +0100, thib´
wrote:

>Martin wrote:
>> On Mon, 14 Jan 2008 23:34:38 -0000, "Paul Lautman"
>> wrote:
>>
>>> 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´

Thanks, thib'

Here's what I've ended up with:

$FTS = date("m/d/y h:i:s A",strtotime(odbc_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.

Re: How to format a date?

am 15.01.2008 09:50:52 von Luuk

"Martin" schreef in bericht
news:cbtno3drn5bbvvgfttr4ftjq3r2vvk6vcg@4ax.com...
> On Mon, 14 Jan 2008 23:34:38 -0000, "Paul Lautman"
> wrote:
>
>>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 ;) ]

Re: How to format a date?

am 15.01.2008 12:24:18 von Captain Paralytic

On 14 Jan, 23:59, Martin wrote:
> On Mon, 14 Jan 2008 23:34:38 -0000, "Paul Lautman"
>
>
>
> wrote:
> >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.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".

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.