Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Štvrtok, 26. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Date format problem

phpMyEdit General     Date format problem
Odoslať novú tému   Odpovedať na tému    
 
riz     Založený: 22.06.2004   Príspevky: 3  
Príspevok Zaslal: 2004-06-22 10:51
Návrat hore  Odpovedať s citátom     

hi, I'm italian and I need to see date format "dd-mm-yyyy" and write "yyyy-mm-dd" in Mysql.

Ok this is my code:

Kód:

$opts['fdd']['data'] = array(
  'name'     => 'Data',
  'select'   => 'T',
  'maxlen'   => 10,
  'default'  => '00-00-0000',
  'help'  => 'formato data (gg-mm-aaaa)',
  'required' => true,
  'sort'     => true,
  'sqlw'     => 'concat(substring($val_qas, 7, 4), "-", substring($val_qas, 4, 2), "-", substring($val_qas, 1, 2))',
  'datemask' => 'd-m-Y'
);


Viev, Add, List, Delete -> Ok
when I Change a record I see the "yyyy-mm-dd" format ... any suggestion?

bye rIz

 
Ivo     Založený: 03.06.2004   Príspevky: 10  
Príspevok Zaslal: 2004-07-30 14:42
Návrat hore  Odpovedať s citátom     

Apparantly the problem here is that MySQL *has* to get the date in a YYYY-MM-DD format for it to understand. When you want your users to be able to enter the date in another format, you have a problem. Is there any way around this?

I haven't tried your code, but I don't see anything that could rewrite the user-entered date into a format that MySQL understands. I can't get this to work.

 
ajh     Založený: 17.12.2003   Príspevky: 236  
Príspevok Zaslal: 2004-07-30 18:54
Návrat hore  Odpovedať s citátom     

Look at using 'sqlw' and 'sql' to transform the format.

'sql' applies an SQL statement when the row is read...so you'd probably use the "DATE_FORMAT" function to get the format into what you want.

'sqlw' is used when you write the record..so you can apply an SQL expression to the string vale in the form to turn it into anything you want. Here you probably want the "STR_TO_DATE" function.

 
Ivo     Založený: 03.06.2004   Príspevky: 10  
Príspevok Zaslal: 2004-08-02 16:41
Návrat hore  Odpovedať s citátom     

Yeah, 'sql' and 'sqlw' seem much more elegant. My 'sql' solution for reading works fine, but (as you can read in my other topic about date formatting) my 'sqlw' gives me an SQL error for an unknown reason... even while using $val or whatever.

 
Sirul     Založený: 26.11.2004   Príspevky: 1  
Príspevok Zaslal: 2004-11-26 20:26
Návrat hore  Odpovedať s citátom     

The solution is just done in the first post. I'm spanish so we use the same date format and was looking for something to help me, and it's just to make this:

Kód:

$opts['fdd']['fecha'] = array(
  'name'     => 'Fecha',
  'select'   => 'T',
  'maxlen'   => 10,
  'default'  => '00-00-0000',
  'sql' => 'concat(substring(fecha, 9, 2), "/", substring(fecha, 6, 2), "/", substring(fecha, 1, 4))',
  'sqlw' => 'concat(substring($val_qas, 7, 4), "-", substring($val_qas, 4, 2), "-", substring($val_qas, 1, 2))',
  'required' => true,
  'sort'     => true
);


sqlw is the same as in the question, and instead of use datemask, i've used a sql function "inverse" to the sqlw one. For me it's working fine.

 
elmonty     Založený: 13.03.2005   Príspevky: 3  
Príspevok Zaslal: 2005-03-13 17:06
Návrat hore  Odpovedať s citátom     

phpMyEdit is wonderful -- except for its handling of dates. I am trying to allow my users to edit dates in MM/DD/YYYY format, but they can also leave the date empty, in which case I want to store NULL.

Here's my code:

Kód:

'sql'  => 'IF(Expires IS NULL,"",DATE_FORMAT(Expires, "%m/%d/%Y"))',
'sqlw' => 'IF($val_qas="",NULL,STR_TO_DATE($val_qas, "%m/%d/%Y"))'


The problem is that if the user enters an empty date, the sqlw evaluates to this:

IF($val_qas="",NULL,STR_TO_DATE("", "%m/%d/%Y"))

This gives a MySQL error, because even though $val_qas="" is true, MySQL still evaluates all the expressions in the IF() function, and STR_TO_DATE("", "%m/%d/%Y") generates the error.

I don't want to use substrings to parse the date into MySQL format, because I don't want to assume that the user has entered a two-digit month or a two-digit day.

There's got to be an easier way to handle dates in phpMyEdit! This is such a basic functionality!

 
Paulo Fernando     Založený: 05.10.2014   Príspevky: 19  
Príspevok Zaslal: 2016-03-11 21:36
Návrat hore  Odpovedať s citátom     

Work for me ! Thanks mans

 
doug     Založený: 10.02.2003   Príspevky: 1013   Bydlisko: Denver, Colorado (USA)
Príspevok Zaslal: 2016-03-11 21:59
Návrat hore  Odpovedať s citátom     

elmonty Napísal:
There's got to be an easier way to handle dates in phpMyEdit! This is such a basic functionality!


Consider finding and implementing a JavaScript datepicker.

Otherwise, user input should be evaluated using triggers, at which point you can create the YYYY-MM-DD MySQL format by evaluating what the user entered. Insert and Update triggers would probably be the same script.

http://opensource.platon.org/projects/doc.php/phpMyEdit/html/configuration.triggers.html

 
Paulo Fernando     Založený: 05.10.2014   Príspevky: 19  
Príspevok Zaslal: 2016-03-12 08:48
Návrat hore  Odpovedať s citátom     

$opts['fdd']['data'] = array(
'name' => 'Data',
'select' => 'T',
'maxlen' => 10,
'default' => date("d/m/Y"),
'sql' => 'concat(substring(data, 9, 2), "/", substring(data, 6, 2), "/", substring(data, 1, 4))',
'sqlw' => 'concat(substring($val_qas, 7, 4), "-", substring($val_qas, 4, 2), "-", substring($val_qas, 1, 2))',
'required' => true,
'sort' => true
);

This work fine !

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov