Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, March 29, 2024
About Us
Magazine
Open Source
CVS
Services
Index  »  Projects  »  phpMyEdit  »  Forum  »  Date format problem

phpMyEdit General     Date format problem
Post new topic   Reply to topic   Goto page 1, 2, 3  Next  
 
riz     Joined: 22 Jun 2004   Posts: 3  
Post Posted: 2004-06-22 10:51
Back to top  Reply with quote     

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:

Code:

$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     Joined: 03 Jun 2004   Posts: 10  
Post Posted: 2004-07-30 14:42
Back to top  Reply with quote     

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     Joined: 17 Dec 2003   Posts: 236  
Post Posted: 2004-07-30 18:54
Back to top  Reply with quote     

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     Joined: 03 Jun 2004   Posts: 10  
Post Posted: 2004-08-02 16:41
Back to top  Reply with quote     

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     Joined: 26 Nov 2004   Posts: 1  
Post Posted: 2004-11-26 20:26
Back to top  Reply with quote     

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:

Code:

$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     Joined: 13 Mar 2005   Posts: 3  
Post Posted: 2005-03-13 17:06
Back to top  Reply with quote     

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:

Code:

'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     Joined: 05 Oct 2014   Posts: 19  
Post Posted: 2016-03-11 21:36
Back to top  Reply with quote     

Work for me ! Thanks mans

 
doug     Joined: 10 Feb 2003   Posts: 1013   Location: Denver, Colorado (USA)
Post Posted: 2016-03-11 21:59
Back to top  Reply with quote     

elmonty wrote:
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     Joined: 05 Oct 2014   Posts: 19  
Post Posted: 2016-03-12 08:48
Back to top  Reply with quote     

$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 !

 
sannyloi22     Joined: 07 Sep 2022   Posts: 55  
Post Posted: 2022-09-07 08:01
Back to top  Reply with quote     

Our licensed and bonded contractors are experts in their field and know the ins and outs of tile installation.
Fair Oaks Pro Tree Service

 
danverseak2     Joined: 07 Sep 2022   Posts: 62  
Post Posted: 2023-01-06 02:48
Back to top  Reply with quote     

We’ll come to your location and quickly diagnose the problem with your heater, so you can get back on the road.

Valdosta Truck Repair (Mobile Only)

 
danverseak2     Joined: 07 Sep 2022   Posts: 62  
Post Posted: 2023-06-27 06:08
Back to top  Reply with quote     

If you reside in a big city, you probably stand a good chance of discovering resources for help with sexual addiction not too far from your house. See: www.moralsupportcoach.com/help

 
todadir332     Joined: 09 Aug 2023   Posts: 485  
Post Posted: 2024-02-11 08:32
Back to top  Reply with quote     

If you are looking for more information about flat rate locksmith Las Vegas check that right away. weight loss personal trainer in Casselberry

 
todadir332     Joined: 09 Aug 2023   Posts: 485  
Post Posted: 2024-02-12 14:55
Back to top  Reply with quote     

I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. cyber security

 
deriel     Joined: 09 Aug 2023   Posts: 359  
Post Posted: 2024-02-15 09:38
Back to top  Reply with quote     

I gotta favorite this website it seems very helpful . childrens watch phone

 
Post new topic   Reply to topic   Goto page 1, 2, 3  Next  

Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top · Feedback form · Application form
Report bug on PLATON.SK website · Terms of use · Privacy policy