Adapting to a Different Server Date Format

Description

The application developer created a grid with a search component with a date field. The Application Server was located on a machine where the regional settings were set for US dates (i.e. MM/DD/YYYY ). The users, however, wanted to search using DD/MM/YYYY date formats. The solution was to edit the .A5W page that displays the component.

The FixDateString() function makes it possible to adapt a web application used by persons who expect a YMD date format to a Application Server that uses a MDY date format.

Assume that your component name is grid1 and that the date field is called date1. Note that component name is actually set in this code block with the command.

with tmpl 
 componentname = "grid1" 
 end with
  • Create the grid component with the search form. The search form has a date field named date1.

  • Place the grid component on an A5W page.

  • Display the Source tab of the HTML Editor.

  • Add the following code after the tag. Note that the variable names have the form: componentName_s_fieldname.

<%a5

if eval_valid("grid1_s_date1") then 
 if grid1_s_date1 <> "" then 
 grid1_s_date1 = "" + date_value( val( word(grid1_s_date1, 3, "-") ), val( word(grid1_s_date1, 2, "-") ), val( word(grid1_s_date1, 1, "-") ) ) 
 end if 
 end if 
 %>

When the user clicks the search button, the variables are submitted with the page. The date1 search field have a value that looks like 31/12/2015. The above code intercepts this value and changes it to 12/31/2015 before the grid component sees it.