Re: [PHP] how should MS Access DATETIME be handled in PHP?
I don't know if MS Access will behave the same, but in MySQL you can have a query like so: SELECT *, DATE_FORMAT(end_date, '%d %m %Y') as end_date_formatted FROM projects; And it will retrieve all columns from your projects table, plus the extra one you've created on the fly, and it will be named end_date_formatted. HTH, John W On 4/19/06, Bing Du [EMAIL PROTECTED] wrote: Do the search as Richard suggested. MS Access might have a similar function you can use, but you'll need to do some searching yourself to find the answer. Sure. I always appreciate various opinions. I've checked with an Access expert. It can be done for Access like Format([DateFieldName], ). But if fields of date type should be formated as needed in the query, there is one situation in which I'm not clear how that would work. Say, I need to query all the fields from a table which has quite a fields. Some of the fields are of some kind of date type. Enumerating the fields is not feasible. SELECT * from table; So in this case, how should the date fields be formated in the query? Thanks, Bing -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how should MS Access DATETIME be handled in PHP?
On Wed, April 19, 2006 9:38 am, Bing Du wrote: Do the search as Richard suggested. MS Access might have a similar function you can use, but you'll need to do some searching yourself to find the answer. Sure. I always appreciate various opinions. I've checked with an Access expert. It can be done for Access like Format([DateFieldName], ). But if fields of date type should be formated as needed in the query, there is one situation in which I'm not clear how that would work. Say, I need to query all the fields from a table which has quite a fields. Some of the fields are of some kind of date type. Enumerating the fields is not feasible. SELECT * from table; So in this case, how should the date fields be formated in the query? If you've got too many fields in the table to enumerate them all and apply Format() to them, then you've got MUCH bigger problems on your hands than date format... :-^ That said, there MAYBE is some kind of introspection function in whatever you are using to find out which fields are date type and which are not. PHP and MySQL have it as: http://php.net/mysql_field_type So you should be able to come up with a script that: #1. Examines the table and finds all the fields of type: 'date' #2. Constructs a query that gets all the fields, but for those of type 'date' wraps Format(date, '-MM-DD HH:II:SS') around them. (Or whatever you need to get what you want) #3. Send your programmatically-constructed query to the database to get the data you want, the way you want it. #4. Drive-through Burger King. You're on your own to actually find the functions that do the introspection, if they exist for Access. Ain't nobody got enough money to make me actually use Access. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how should MS Access DATETIME be handled in PHP?
I don't know if MS Access will behave the same, but in MySQL you can have a query like so: SELECT *, DATE_FORMAT(end_date, '%d %m %Y') as end_date_formatted FROM projects; And it will retrieve all columns from your projects table, plus the extra one you've created on the fly, and it will be named end_date_formatted. Great. Thanks, John. Yes, it works for Access as well. Bing -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how should MS Access DATETIME be handled in PHP?
Do the search as Richard suggested. MS Access might have a similar function you can use, but you'll need to do some searching yourself to find the answer. Sure. I always appreciate various opinions. I've checked with an Access expert. It can be done for Access like Format([DateFieldName], ). But if fields of date type should be formated as needed in the query, there is one situation in which I'm not clear how that would work. Say, I need to query all the fields from a table which has quite a fields. Some of the fields are of some kind of date type. Enumerating the fields is not feasible. SELECT * from table; So in this case, how should the date fields be formated in the query? Thanks, Bing -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how should MS Access DATETIME be handled in PHP?
On 4/14/06, Bing Du [EMAIL PROTECTED] wrote: While all the data-munging in PHP is very interesting... Might I suggest that you just use MySQL's date_format() function to ask MySQL to give you the data you want in the first place? Some purists would claim that the database is not the place to put presentation logic, of course. And for a large-scale library where other users might want to skin a different format, I couldn't agree more. But, really, for a small project, K.I.S.S. wins out, and having MySQL just hand you what you want instead of cluttering up your code with several lines (or a long multi-operation line) of PHP, seems like a cleaner solution. Not to mention that you'll have a lot less headaches like this one. http://mysql.com and search for date_format Thanks, Richard. I agree with you. Is date_format() a MySQL specific funtion? If so, we're out of luck because our backend DB is MS Access. Do the search as Richard suggested. MS Access might have a similar function you can use, but you'll need to do some searching yourself to find the answer. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how should MS Access DATETIME be handled in PHP?
While all the data-munging in PHP is very interesting... Might I suggest that you just use MySQL's date_format() function to ask MySQL to give you the data you want in the first place? Some purists would claim that the database is not the place to put presentation logic, of course. And for a large-scale library where other users might want to skin a different format, I couldn't agree more. But, really, for a small project, K.I.S.S. wins out, and having MySQL just hand you what you want instead of cluttering up your code with several lines (or a long multi-operation line) of PHP, seems like a cleaner solution. Not to mention that you'll have a lot less headaches like this one. http://mysql.com and search for date_format Thanks, Richard. I agree with you. Is date_format() a MySQL specific funtion? If so, we're out of luck because our backend DB is MS Access. Bing -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] how should MS Access DATETIME be handled in PHP?
Hello, We have a website which pulls data from its MS Access backend database and publishes the data using Cold Fusion. The Cold Fusion code has '#DateFormat(end_date, Mmmm d, )#'. 'end_date' is a table column of type DATETIME in the Access DB. Now, we need to use PHP instead of Cold Fusion to query the same Access database and display the data on the web. Here are the related PHP code snippets. Query the Access DB: $qry = odbtp_query(SELECT end_date,title,projectID FROM projects ORDER BY end_date DESC); Get the query results: while( ($rec = odbtp_fetch_array($qry)) ) { echo end_date is $rec[0]br; } The outputs of the above echo are: end_date is Object end_data is Object The date format I want the output to be is like 'March 31, 2005'. I've tried PHP's date() function using format 'F j, Y'. The format looks correct. But date() requires the time it's converting be a timestamp. So how should I output the 'end_date' in the 'F j, Y' format? I'd appreciate any help. Bing -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how should MS Access DATETIME be handled in PHP?
Bing Du wrote: Hello, We have a website which pulls data from its MS Access backend database and publishes the data using Cold Fusion. The Cold Fusion code has '#DateFormat(end_date, Mmmm d, )#'. 'end_date' is a table column of type DATETIME in the Access DB. Now, we need to use PHP instead of Cold Fusion to query the same Access database and display the data on the web. Here are the related PHP code snippets. Query the Access DB: $qry = odbtp_query(SELECT end_date,title,projectID FROM projects ORDER BY end_date DESC); Get the query results: while( ($rec = odbtp_fetch_array($qry)) ) { echo end_date is $rec[0]br; apparently $rec[0] is a php object - try the following lines to find out what's inside: echo 'pre'; print_r($rec[0]); echo 'pre'; that will probably give you a clue as to how to extract some useful info from the object. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how should MS Access DATETIME be handled in PHP?
apparently $rec[0] is a php object - try the following lines to find out what's inside: echo 'pre'; print_r($rec[0]); echo 'pre'; that will probably give you a clue as to how to extract some useful info from the object. Excellent! Yes, it now does give me a clue to see what's actually in the object. print_r($rec[0]) shows: stdClass Object ( [year] = 2005 [month] = 8 [day] = 31 [hour] = 0 [minute] = 0 [second] = 0 [fraction] = 0 ) I've never dealt with object in PHP. Something new learnt today. I'm now able to use get_object_vars($rec[0]) to extract the info from the object. There is one thing I don't understand though. Is there anything wrong with the follow code snippet? The result of echo is 'using list, year is rather than 'using list, year is 2005'. == list($year,$month,$day,$hour,$minute,$second,$fraction) = get_object_vars($rec[0]); echo using list, year is $yearbr; == This one works. But I prefer using list. == $arr = get_object_vars($rec[0]); echo year is $arr[year]br; == Thanks, Bing -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how should MS Access DATETIME be handled in PHP?
Bing Du wrote: apparently $rec[0] is a php object - try the following lines to find out what's inside: echo 'pre'; print_r($rec[0]); echo 'pre'; that will probably give you a clue as to how to extract some useful info from the object. Excellent! Yes, it now does give me a clue to see what's actually in the object. print_r($rec[0]) shows: stdClass Object ( [year] = 2005 [month] = 8 [day] = 31 [hour] = 0 [minute] = 0 [second] = 0 [fraction] = 0 ) I've never dealt with object in PHP. Something new learnt today. I'm now able to use get_object_vars($rec[0]) to extract the info from the object. There is one thing I don't understand though. Is there anything wrong with the follow code snippet? The result of echo is 'using list, year is rather than 'using list, year is 2005'. == list($year,$month,$day,$hour,$minute,$second,$fraction) = get_object_vars($rec[0]); echo using list, year is $yearbr; == This one works. But I prefer using list. I hate list. each to his own :-) try this (untested): list($year,$month,$day,$hour,$minute,$second,$fraction) = array_values(get_object_vars($rec[0])); no go and read the manual about what list does exactly and do some digging as to the wonders of php arrays (there are numeric indexes and there are associative indexes, and they can be mixed) as penance. then learn to love associative arrays (e.g. what get_object_vars() returns) because: a. they are everywhere in php. b. they are lovely (thats a fact - as stalin would say) ;-) == $arr = get_object_vars($rec[0]); echo year is $arr[year]br; oh and quote your keys when using associative arrays: echo year is {$arr['year']}br; or echo year is $arr['year']br; or echo year is ,$arr['year'],br; why you ask? turn on error reporting to full and or read the manual to find out. == Thanks, Bing -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how should MS Access DATETIME be handled in PHP?
Hi! Bing Du wrote: Excellent! Yes, it now does give me a clue to see what's actually in the object. print_r($rec[0]) shows: stdClass Object ( [year] = 2005 [month] = 8 [day] = 31 [hour] = 0 [minute] = 0 [second] = 0 [fraction] = 0 ) I've never dealt with object in PHP. Something new learnt today. I'm now able to use get_object_vars($rec[0]) to extract the info from the object. You don't need get_object_vars(), you can simply use $rec[0]-year; Perhaps have a look at the docs: http://de3.php.net/oop5 And perhaps the following example is useful for you: http://odbtp.sourceforge.net/timetable.html#list regards Andreas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how should MS Access DATETIME be handled in PHP?
I hate list. each to his own :-) try this (untested): list($year,$month,$day,$hour,$minute,$second,$fraction) = array_values(get_object_vars($rec[0])); Magic! That works. In this case, I'd like to use list because I can use the vars directly (e.g. $year) rather than $arr['year']. I need to use the date as key to construct another associative array. It's easier for me to do $projects[$year] instead of $projects[$arr['year']]. Thanks also for your other advice. I appreciated it. Bing -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how should MS Access DATETIME be handled in PHP?
Hi! Bing Du wrote: Excellent! Yes, it now does give me a clue to see what's actually in the object. print_r($rec[0]) shows: stdClass Object ( [year] = 2005 [month] = 8 [day] = 31 [hour] = 0 [minute] = 0 [second] = 0 [fraction] = 0 ) I've never dealt with object in PHP. Something new learnt today. I'm now able to use get_object_vars($rec[0]) to extract the info from the object. You don't need get_object_vars(), you can simply use $rec[0]-year; Ah, great. Thanks much for the tip and the pointers. That's even better. Another question. It's not hard to do this mapping. But if given a month like '9', is there any PHP function that can convert it to a full text month name 'September'? Bing -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] how should MS Access DATETIME be handled in PHP?
On 13 April 2006 17:08, Bing Du wrote: Hi! Bing Du wrote: Excellent! Yes, it now does give me a clue to see what's actually in the object. print_r($rec[0]) shows: stdClass Object ( [year] = 2005 [month] = 8 [day] = 31 [hour] = 0 [minute] = 0 [second] = 0 [fraction] = 0 ) I've never dealt with object in PHP. Something new learnt today. I'm now able to use get_object_vars($rec[0]) to extract the info from the object. You don't need get_object_vars(), you can simply use $rec[0]-year; Ah, great. Thanks much for the tip and the pointers. That's even better. Another question. It's not hard to do this mapping. But if given a month like '9', is there any PHP function that can convert it to a full text month name 'September'? Yes. Oh, you want to know what it is? I expect there's actually several ways, although I'm thinking it's likely that none of them is blindingly obvious. Personally, I think I'd be inclined to do it like this: $mth = 9; echo date('F', mktime(12,0,0, $mth)); I'm sure you'll get other equally valid suggestions! Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] how should MS Access DATETIME be handled in PHP?
I expect there's actually several ways, although I'm thinking it's likely that none of them is blindingly obvious. Personally, I think I'd be inclined to do it like this: $mth = 9; echo date('F', mktime(12,0,0, $mth)); Interesting. Thanks a bunch for the tip, Mike. Appreciate it. Bing -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how should MS Access DATETIME be handled in PHP?
On Thu, April 13, 2006 9:30 am, Bing Du wrote: $qry = odbtp_query(SELECT end_date,title,projectID FROM projects ORDER BY end_date DESC); While all the data-munging in PHP is very interesting... Might I suggest that you just use MySQL's date_format() function to ask MySQL to give you the data you want in the first place? Some purists would claim that the database is not the place to put presentation logic, of course. And for a large-scale library where other users might want to skin a different format, I couldn't agree more. But, really, for a small project, K.I.S.S. wins out, and having MySQL just hand you what you want instead of cluttering up your code with several lines (or a long multi-operation line) of PHP, seems like a cleaner solution. Not to mention that you'll have a lot less headaches like this one. http://mysql.com and search for date_format -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php