Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > help with dates, MySQL to PHP

help with dates, MySQL to PHP
Thread Tools
Fresh-Faced Recruit
Join Date: Mar 2001
Location: Arlington, VA 22206
Status: Offline
Reply With Quote
Sep 30, 2002, 09:12 PM
 
Here is the answer to my question of how to format a MySQL date or time field in PHP:
Dreamweaver recordset: row_signup_list
MySQL Date record: task_date
MySQL Time record: task_time_start

Thanks to google's search of the Dreamweaver newsgroup and a second night on the internet I got it working:
[php] <?php $date= $row_signup_list['task_date']; $date=explode("-",$date); echo"$date[1]-$date[2]-$date[0]"; ?> [/php]
(to make format: 10-18-2002)

And it also had the time!

[php] <?php $temptime = strtotime($row_signup_list['task_time_start']); $thetime = date("g:i a",$temptime); echo "$thetime"; ?> [/php]
(to make format: 11:04 am)

Hope this is of use to someone.
Thank you,
iolaire

--- old post --
Using Dreamweaver I'm trying to set up a simple website where someone
can sign up for a volunteer task. Right now I'm running against a wall
trying to re-format a date from a MySQL date field (0000-00-00) to
(12-31-2002. My Dreamweaver record-set is signup_list and my date
field is task_date.

It seems like I should be able to use some simple code to format it in
Month Day Year format. However, this is as close as I can get:
[php] <?php echo date('M-d-Y',$row_signup_list['task_date']); ?> [/php]
and that generates a date of Dec 31 1969 regardless of what is in the
database field.

Looking online it seems like the PHP date function is usually used to
calculate a future date form the current date or generate the current
date. Otherwise there are complex codes relating to the UNIX Timestamp
function.

Please can someone tell how to format a MySQL date via PHP?
Thank you,
iolaire


(If there is any easy way to add it to the select statment, that would
be fine.)
SELECT *
FROM tasks, event
WHERE event.event_id = tasks.task_event AND tasks.task_event = picktask
(picktask is a variable passed from the previous page)
(Last edited by iolaire; Oct 1, 2002 at 09:43 AM. )
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Oct 1, 2002, 05:40 PM
 
Originally posted by iolaire:
SELECT *
FROM tasks, event
WHERE event.event_id = tasks.task_event AND tasks.task_event = picktask
(picktask is a variable passed from the previous page)
Why do it the hard way? Try this command in your SQL query:

SELECT DATE_FORMAT(task_date,'%d %m %Y') FROM tasks

and you've got your pre-formatted date. Check out
this page for more commands.
Computer thez nohhh...
     
iolaire  (op)
Fresh-Faced Recruit
Join Date: Mar 2001
Location: Arlington, VA 22206
Status: Offline
Reply With Quote
Oct 2, 2002, 07:26 AM
 
Thank you Simon,
That is the type of simple answer that I was looking for.
iolaire
     
Junior Member
Join Date: Nov 1999
Status: Offline
Reply With Quote
Oct 20, 2002, 11:16 PM
 
Right on, Simon. More people need to harness the simple powers of SQL before commanding PHP to plow through a lot of calculations.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:52 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2