FromStringToDate.xml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
  4. <sect1 id="FromStringToDate">
  5. <title>FromStringToDate</title>
  6. <para><emphasis role="bold">STD.Date.FromStringToDate<indexterm>
  7. <primary>STD.Date.FromStringToDate</primary>
  8. </indexterm><indexterm>
  9. <primary>Date.FromStringToDate</primary>
  10. </indexterm><indexterm>
  11. <primary>FromStringToDate</primary>
  12. </indexterm>(</emphasis> <emphasis>date_text, format</emphasis> <emphasis
  13. role="bold">)</emphasis></para>
  14. <informaltable colsep="1" frame="all" rowsep="1">
  15. <tgroup cols="2">
  16. <colspec colwidth="80.50pt" />
  17. <colspec />
  18. <tbody>
  19. <row>
  20. <entry><emphasis>date_text</emphasis></entry>
  21. <entry>The string to be converted</entry>
  22. </row>
  23. <row>
  24. <entry><emphasis>format</emphasis></entry>
  25. <entry>The format of the input string. See strftime documentation
  26. for details (<ulink
  27. url="http://strftime.org/">http://strftime.org/</ulink>)</entry>
  28. </row>
  29. <row>
  30. <entry>return</entry>
  31. <entry>The date that was matched in the string. Returns 0 if failed
  32. to match or if the date components match but the result is an
  33. invalid date.</entry>
  34. </row>
  35. </tbody>
  36. </tgroup>
  37. </informaltable>
  38. <para>The <emphasis role="bold">FromStringToDate</emphasis> function
  39. converts a string to a Date_t using the relevant string format. </para>
  40. <para>If the resulting date must be representable within the Gregorian
  41. calendar after the year 1600, you should use the
  42. Std.Date.IsValidGregorianDate() function to determine its validity.</para>
  43. <para><programlisting>Supported characters:
  44. %B Full month name
  45. %b or %h Abbreviated month name
  46. %d Day of month (two digits)
  47. %e Day of month (two digits, or a space followed by a single digit)
  48. %m Month (two digits)
  49. %t Whitespace
  50. %y year within century (00-99)
  51. %Y Full year (yyyy)
  52. %j Julian day (1-366)
  53. Common date formats
  54. American '%m/%d/%Y' mm/dd/yyyy
  55. Euro '%d/%m/%Y' dd/mm/yyyy
  56. Iso format '%Y-%m-%d' yyyy-mm-dd
  57. Iso basic '%Y%m%d' yyyymmdd
  58. '%d-%b-%Y' dd-mon-yyyy e.g., '21-Mar-1954'
  59. </programlisting></para>
  60. <para>Example:</para>
  61. <programlisting format="linespecific">IMPORT STD;
  62. D1 := STD.Date.FromStringToDate('19720607', '%Y%m%d');
  63. //D1 contains 19720607
  64. D2 := STD.Date.FromStringToDate('19720007', '%Y%m%d');
  65. //D2 contains 0
  66. D3 := STD.Date.FromStringToDate('4/29/1974', '%m/%d/%Y');
  67. //D3 contains 19740429
  68. D4:= STD.Date.FromStringToDate('29/4/1974', '%d/%m/%Y');
  69. //D4 contains 19740429
  70. </programlisting>
  71. <para>See Also: <link
  72. linkend="IsValidGregorianDate">IsValidGregorianDate</link></para>
  73. </sect1>