![]() |
|
#1
|
|||
|
|||
Rookie problem with date formatHelp please. I am very new to PHP and mysql, and am trying to write a simple script to display tide tables for my area. My problem is this: My tides data in the database uses the default mysql time format (ex. 22:17:32) and I would like the output of my query to be displayed as 10:17 PM (with no seconds). My query is executed as "Select * from `tides` where `date` = NOW()" and works fine except for the time format. I have played with DATE_FORMAT() as described on the MySQL homepage and in the article on this site, but can't get the query to execute as I assume it has to mach the data in the database. Maybe DATE_FORMAT() would work when querying for a specifc date, but not sure how to implement it with SELECT * and the variable NOW(). Should I be affecting the output via PHP date formats or MySQL date formats? Thanks for the help and the patience. DM
|
|||
|
#2
|
||||
|
||||
|
Hello cave monkey,
Basically, you can use DATE_FORMAT() for this but just in case I've misunderstood your question, you should also try using TIME_FORMAT(). Here's an example: PHP Code:
It goes without saying that there MUST be a record that matches the time EXACTLY, down to the seconds, for it to return a result. If you want it to match a range of time, then just reply with the details. __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#3
|
|||
|
|||
Thanks!Thanks for your response. I found a similar solution through trial and error before reading your post. My final query used TIME_FORMAT() as you recommend....
PHP Code:
|
|
#4
|
||||
|
||||
|
Yes, it's possible but I don't think that's such a good idea.
It's also normal to use multiple AS (or aliases) in your queries; although I don't see it in your example above. __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#5
|
|||
|
|||
|
Thanks again for the help. It's appreciated.
|
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem with php5 cgi installation | fab13 | Apache Web Server Forum | 3 | 19-Nov-2003 10:11 |
| Time Problem in Program | MrSmiley | C Programming Language | 1 | 03-Nov-2003 13:00 |
| unwanted scrollbar problem | kelly001 | Web Design Forum | 3 | 24-Oct-2003 11:44 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The