Tags:
create new tag
view all tags

Question

For the country (Spain) I'm working in, the usual format for entering dates is dd/mm/aaaa. I have a form with two dates, one for planned delivery and another for actual, and need to calculate the difference, in days, between the two. They are both defined as text in the form. If I could use the US mm/dd/aaaa date format, there would be no problem, I could use the Spreadsheet TIME AND TIMEDIFF functions, but that format would originate confusion for the user. I was hoping to find some Spreadsheet funcion, some kind of Substring or Mid, that I could use in order to a temporary format change from dd/mm/aaaa to mm/dd/aaaa, but I can't find anything appropriate. Thanks in advance for ideas/workarounds.

Environment

TWiki version: TWikiRelease04x00x05
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: HP-UX hp2 B.11.11 U 9000/800
Web server: Apache 3.0.99-563
Perl version: 5.6.1
Client OS: Win XP Pro SP4
Web Browser: MS Internet Explorer 6
Categories: Forms, Plugins

-- RalphEllison - 11 Jan 2007

Answer

ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.

I know, the dd/mm/yyyy date in the USA with mid-endian format is about as confusing as it can get. Nevertheless, there is help in converting the format.

You can do that by setting variables and $REPLACE(). Assuming a format with fixed width (e.g. zero padded days and month) you can do this: (view raw to see how)

  • Set dd/mm/yyyy date: 31/12/2006
  • Set dd: 31
  • Set mm: 12
  • Set yyyy: 2006
  • Set mm/dd/yyyy format: 12/31/2006

You can combine that into one long formula:

  • Set dd/mm/yyyy date: 31/12/2006
  • Set mm/dd/yyyy format: 12/31/2006

If you want to support also formats that have no zero padding such as 5/3/2006, you can use a $FIND() to find the position of the slash.

  • Set dd/mm/yyyy date: 5/12/2006
  • Set dd: 5
  • Set mm: 12
  • Set yyyy: 2006
  • Set mm/dd/yyyy format: 12/5/2006

Also this you can combine that into one long formula:

  • Set dd/mm/yyyy date: 5/12/2006
  • Set mm/dd/yyyy format: 12/5/2006

The result can be used in $TIME() and $TIMEDIFF().

If you want to re-use the conversion formula you can store the formula in a variable using $NOEXEC() and use it with an $EXEC(). See doc at SpreadSheetPlugin

-- PeterThoeny - 11 Jan 2007

Thanks Peter, very clear. I think I need to upgrade to use EXEC, but no great problem.

-- RalphEllison - 12 Jan 2007

Change status to:
Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2007-01-12 - RalphEllison
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.