I think we'd have to know more about both your environment and the MySQL server's to answer the "Why?". POSIX::strftime honors locale, so the value of $date depends on your LC_foo environment variables. MySQL may be compiled to store utf-8 or some other character encoding.
Question a): I think you should store datetime fields the way MySQL wants, as a datetime column type. Storing them as strings denies you the very useful builtin date & time functions of MySQL. You can retrieve datetimes with MySQL's DATE_FORMAT() function to get most any representation you want. If you have serious encoding problems, you can fall back on unix epoch time for retrieval and then apply localtime.
Question b): Some browsers pretty much ignore http headers. Try specifying the character encoding in the html tag, as well.
| [reply] |
If you want to keep your datetime value in your own format, you better store it in a CHAR or VARCHAR type of field rather than in a DATETIME or timestamp type of field.
CountZero "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
| [reply] |
From the docs of MySQL:
DATE_FORMAT(date,format)
Formats the date value according to
the format string.
The following specifiers may be used in the
format string. The
‘%’ character is required
before format specifier characters.
Ranges for the month and day specifiers begin with zero due to
the fact that MySQL allows the storing of incomplete dates
such as '2004-00-00'.
mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00', '%W %M %Y');
-> 'Saturday October 1997'
mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00', '%H:%i:%s');
-> '22:23:00'
mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00',
'%D %y %a %d %m %b %j');
-> '4th 97 Sat 04 10 Oct 277'
mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00',
'%H %k %I %r %T %S %w');
-> '22 22 10 10:23:00 PM 22:23:00 00 6'
mysql> SELECT DATE_FORMAT('1999-01-01', '%X %V');
-> '1998 52'
mysql> SELECT DATE_FORMAT('2006-06-00', '%d');
-> '00'
This allows you to format your DATETIME or TIMESTAMP fields, but it doesn't seem to honor your locale setting. As a matter of fact, MySQL does not seem to know how to set the locale at all. It can however set on a per table basis the character set to use (latin1, UTF8, ...). If you really want to have your DATETIME fields in Greek, have a look at DBIx::Class and its inflate/deflate mechanism or the ColumnHandlers method from DBIx::DataModel which can transform your fields in pretty any way you like.
CountZero "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
| [reply] [d/l] [select] |
And why do i need to use encode to switch from greek => utf8?
| [reply] |
| [reply] |
Pardon me for asking stupid questions, but why aren't you just doing something like:
INSERT INTO mytable (mydatetimefield) values (NOW());
mySQL accepts NOW() input for datetime fields, and there's no need to mess with formatting it yourself. | [reply] [d/l] |
sub now {
my @time = localtime;
return sprintf '%d-%02d-%02d %02d:%02d:%02d',
$time[5]+1900, $time[4]+1, $time[3], $time[2], $time[1], $
+time[0];
# year month day hour min
+sec
}
?
| [reply] [d/l] |