Looking back over this, I’m wondering what the % signs are doing in
there at all. Are these the PHP date() format or something else?
Also, the last three lines are contradicting themselves. $formatted is
what you want to return, the next two lines basically do the same
thing again, but without referring to the timestamp that you generated
in MAR. If you leave off the second argument to date(), it acts as if
you want to have the formatted version of right now.
And if all you want to get from the function is the current date,
formatted as you indicate, you could simply do this"
return date('l, F j, Y',time()); //that's a lower-case L for the first
format token
See what happens on your server if you run the following snippet of
PHP all by itself:
<?php
$now = date('l, F j, Y',time());
print $now . "n";
$timestamp = strtotime($now);
print date('Y-M-D',$timestamp);
?>
If this works, then you should see the same date formatted two
different ways. If it doesn’t, then the second one will be something
besides the current date.
strtotime() is pretty flexible about what form it gets a date in, and
usually does a yeoman job of converting a “natural language” input
into a timestamp. But I’m not sure if it can go all the way as you do
here with the day of the week and such. That might throw it off.
All in all, this is pretty fragile. If you allow the end user to edit
a natural language version of the date, you may find it nearly
impossible to trap all possible errors and convert that “date” into
something the computer can reckon with.
The reason you want to use real dates in your database is because
MySQL can do powerful things with sorting them and deciding what range
of records fall between two other dates and such. It’s quite deep. But
if you let the user mess with it at that level, it’s going to be
difficult at best to figure out if what you get out of the edit is
actually the real date or not. strtotime() will probably fail and
produce a time of -1, which date() will turn into December 31, 1969.
Many systems that allow date editing use individual pickers for each
segment of the date, and use JavaScript to force those pickers to
conform, so you would never get February 30th, for example. For simple
systems, I just show the ISO date, as it’s unambiguous, and trust the
user. For something public-facing you want to lock it down more
completely.
And then there’s this: http://www.styledisplay.com/mootoolsdatepicker/
which is the first hit under mootools date picker in the google.
Walter
On Aug 22, 2009, at 2:48 PM, Todd wrote:
Yes, I do want to store the date and translate it into a more
readable format. Am I close with this?
$foo->date = MyActiveRecord::DbDate(); //today
$timestamp = $foo->get_timestamp('date');
$formatted = date('%W, %M %e, %Y',$timestamp);
$date_format = date('%W, %M %e, %Y');
return $date_format;
Btw, CalendarView is nice but I’m using moo.
Todd
On Aug 22, 2009, at 1:29 PM, Walter Lee Davis wrote:
$timestamp = $foo->get_timestamp('date');
$formatted = date('%W, %M %e, %Y',$timestamp);
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options