Connecting Tech Pros Worldwide Forums | Help | Site Map

PHP: DATETIME is Object?

dubing@gmail.com
Guest
 
Posts: n/a
#1: Apr 13 '06
Hello,

We're using PHP to query the Access DB and publish the data on the web.

Query the DB:

$qry = odbtp_query("SELECT end_date,title FROM projects ORDER BY
end_date DESC");

Get the query results:

while( ($rec = odbtp_fetch_array($qry)) ) {
echo "end_date is $rec[0], title is $rec[1]<br>";
}

The outputs are:

end_date is Object, title is 'blah blah'
end_date is Object, title is 'lajd;fsakf'
.....

'end_date' is of type DATETIME in Access. How DATETIME is actually
stored in Acces? Can anybody give me an example? Why PHP shows it as
Object? What should I do if I want end_date to be printed in the 'F j,
Y' format, like 'March 31, 2005'?

I'd appreciate any help.

Bing


AllenWhite
Guest
 
Posts: n/a
#2: Apr 13 '06

re: PHP: DATETIME is Object?


I'm not sure what library you're using to connect to the Access
database - I know I've done this before without problems, but not with
these odbtp functions.

One approach would be to use some of the built-in date format functions
right in your SQL query - something like:

SELECT FORMAT(end_date,'mmmm d, yyyy') AS date, title FROM projects
ORDER BY end_date DESC

David W. Fenton
Guest
 
Posts: n/a
#3: Apr 14 '06

re: PHP: DATETIME is Object?


"AllenWhite" <commerce@allenwhite.net> wrote in
news:1144949655.001992.172830@t31g2000cwb.googlegr oups.com:
[color=blue]
> One approach would be to use some of the built-in date format
> functions right in your SQL query - something like:
>
> SELECT FORMAT(end_date,'mmmm d, yyyy') AS date, title FROM
> projects ORDER BY end_date DESC[/color]

I don't think the Access Expression Service is available from ODBC,
so that won't work.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
MGFoster
Guest
 
Posts: n/a
#4: Apr 14 '06

re: PHP: DATETIME is Object?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

DateTime data types are stored as Double numbers in Access tables.
E.g.:

Now = 4/13/2006 6:25:50 PM and is stored as 38820.7679398148

The integer is the number of days since 12/30/1899 (the ZEROth day).
The decimal is the number of milliseconds since midnight of the
indicated date.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRD76t4echKqOuFEgEQL6VwCg/2C45yozmB2g8NKPFNH9Vh/0U8QAn2wC
Mdz56o0CTfNigL07XbJP/GsJ
=j8Hq
-----END PGP SIGNATURE-----


dubing@gmail.com wrote:[color=blue]
> Hello,
>
> We're using PHP to query the Access DB and publish the data on the web.
>
> Query the DB:
>
> $qry = odbtp_query("SELECT end_date,title FROM projects ORDER BY
> end_date DESC");
>
> Get the query results:
>
> while( ($rec = odbtp_fetch_array($qry)) ) {
> echo "end_date is $rec[0], title is $rec[1]<br>";
> }
>
> The outputs are:
>
> end_date is Object, title is 'blah blah'
> end_date is Object, title is 'lajd;fsakf'
> ....
>
> 'end_date' is of type DATETIME in Access. How DATETIME is actually
> stored in Acces? Can anybody give me an example? Why PHP shows it as
> Object? What should I do if I want end_date to be printed in the 'F j,
> Y' format, like 'March 31, 2005'?
>
> I'd appreciate any help.
>
> Bing
>[/color]
David W. Fenton
Guest
 
Posts: n/a
#5: Apr 14 '06

re: PHP: DATETIME is Object?


MGFoster <me@privacy.com> wrote in
news:VUC%f.3043$BS2.2481@newsread1.news.pas.earthl ink.net:
[color=blue]
> DateTime data types are stored as Double numbers in Access tables.
> E.g.:
>
> Now = 4/13/2006 6:25:50 PM and is stored as 38820.7679398148
>
> The integer is the number of days since 12/30/1899 (the ZEROth
> day). The decimal is the number of milliseconds since midnight of
> the indicated date.[/color]

That is not true. The decimal part is the fraction of a day since
midnight of the day indicated by the integer part. If it were
actually milliseconds, it would be much easier, since there'd be no
rounding inaccuracies.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
MGFoster
Guest
 
Posts: n/a
#6: Apr 14 '06

re: PHP: DATETIME is Object?


David W. Fenton wrote:[color=blue]
> MGFoster <me@privacy.com> wrote in
> news:VUC%f.3043$BS2.2481@newsread1.news.pas.earthl ink.net:
>
>[color=green]
>>DateTime data types are stored as Double numbers in Access tables.
>>E.g.:
>>
>>Now = 4/13/2006 6:25:50 PM and is stored as 38820.7679398148
>>
>>The integer is the number of days since 12/30/1899 (the ZEROth
>>day). The decimal is the number of milliseconds since midnight of
>>the indicated date.[/color]
>
>
> That is not true. The decimal part is the fraction of a day since
> midnight of the day indicated by the integer part. If it were
> actually milliseconds, it would be much easier, since there'd be no
> rounding inaccuracies.
>[/color]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Right you are. I must have been thinking of Unix time.

Therefore, the fraction .7679398148 means that almost 77 percent of the
day has passed.

Seconds in day = 86400

864000 * .7679398148 = 66349.99999872 seconds elapsed since midnight

(66349.99999872 / 60 ) / 60 = 18.4305555552 hours since midnight

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRD/NoYechKqOuFEgEQK21wCgqxAO8A5ujYmyepSCO77zOP+ST94Ao OD1
QCY40t8T07yKR2SJ9TQG+lXt
=vj+C
-----END PGP SIGNATURE-----
Gord
Guest
 
Posts: n/a
#7: Apr 15 '06

re: PHP: DATETIME is Object?


Bing,
[color=blue]
>How DATETIME is actually stored in Acces?
>[...]
>Why PHP shows it as Object?[/color]

Regardless of how Access stores datetime values internally, ODBTP
returns such values as a datetime object by default. You can change
this behaviour with an odbtp.datetime_format entry in PHP.INI...

http://odbtp.sourceforge.net/phpext.html#phpini

....or you can learn how to manipulate ODBTP's datetime object to get
the result you want.

IOW, this isn't really an Access question, it is an ODBTP question.

Closed Thread