Understanding the BizTalk Mapper: Part 6 - Date/Time Functoids#
XSLT v1.0 has no support for Date/Time values, whilst XSLT v2.0 has full support.
Therefore it's not surprising that your only option is to use C#'s rich support for Date/Time values.
And this is why all of the functoids in this category emit inline C#.

For each functoid I've shown:
  1. Whether XSLT or C# is emitted
  2. Whether an XSLT equivalent exists
  3. The XSLT or C# emitted by the functoid
  4. Where C# is emitted, the equivalent XSLT to achieve the same functionality (in both XSLT v1.0 and v2.0)
Functoids covered in this category:
Add Days Time
Date Common Code
Date and Time  

Note:
This is the sixth in a series of 13 posts about the BizTalk Mapper.
The other posts in this series are (links will become active as the posts become active):
Understanding the BizTalk Mapper: Part 1 - Introduction
Understanding the BizTalk Mapper: Part 2 - Functoids Overview
Understanding the BizTalk Mapper: Part 3 - String Functoids
Understanding the BizTalk Mapper: Part 4 - Mathematical Functoids
Understanding the BizTalk Mapper: Part 5 - Logical Functoids
Understanding the BizTalk Mapper: Part 6 - Date/Time Functoids
Understanding the BizTalk Mapper: Part 7 - Conversion Functoids
Understanding the BizTalk Mapper: Part 8 - Scientific Functoids
Understanding the BizTalk Mapper: Part 9 - Cumulative Functoids
Understanding the BizTalk Mapper: Part 10 - Database Functoids
Understanding the BizTalk Mapper: Part 11 - Advanced Functoids
Understanding the BizTalk Mapper: Part 12 - Performance and Maintainability
Understanding the BizTalk Mapper: Part 13 - Is the Mapper the best choice for Transformation in BizTalk?

Download the complete series as a single Microsoft Word document (1.2MB) or Adobe PDF document (620kb).


Date/Time Functoids

Note: XSLT 1.0 has no built-in Date/Time functions, whereas XSLT 2.0/XPath 2.0 does.

 

Add Days

 

 

Generates: C#

Has XSLT Equivalent: in 2.0 only

  Emitted Code:
public string DateAddDays(string date, string days)
{
    string retval = "";
    double db = 0;
    if (IsDate(date) && IsNumeric(days, ref db))
    {
        DateTime dt = DateTime.Parse(date);
        int d = (int)db;
        dt = dt.AddDays(d);
        retval = dt.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
    }
    return retval;
}
 

XSLT 1.0 Equivalent: (none)

  XSLT 2.0 Equivalent: xs:dateTime('2007-12-12') + xdt:dayTimeDuration('PxD')
Where x (in dayTimeDuration()) is number of days to add e.g. 5 days would be 'P5D'
 

 

Date

 

 

Generates: C#

Has XSLT Equivalent: in 2.0 only

  Emitted Code:
public string DateCurrentDate()
{
    DateTime dt = DateTime.Now;
    return dt.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
}
 

XSLT 1.0 Equivalent: (none)

 

XSLT 2.0 Equivalent: fn:current-date()

 

 

Date and Time

 

 

Generates: C#

Has XSLT Equivalent: in 2.0 only

  Emitted Code:
public string DateCurrentDateTime()
{
    DateTime dt = DateTime.Now;
    string curdate = dt.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
    string curtime = dt.ToString("T", System.Globalization.CultureInfo.InvariantCulture);
    string retval = curdate + "T" + curtime;
    return retval;
}
 

XSLT 1.0 Equivalent: (none)

 

XSLT 2.0 Equivalent: fn:current-dateTime()

 

 

Time

 

 

Generates: C#

Has XSLT Equivalent: in 2.0 only

  Emitted Code:
public string DateCurrentTime()
{
    DateTime dt = DateTime.Now;
    return dt.ToString("T", System.Globalization.CultureInfo.InvariantCulture);
}
 

XSLT 1.0 Equivalent: (none)

 

XSLT 2.0 Equivalent: fn:current-date()

   
  Common Code
(this is common code used by all the date/time functoids)
  public bool IsNumeric(string val)
{
    if (val == null)
    {
        return false;
    }
    double d = 0;
    return Double.TryParse(val, System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out d);
}
 
public bool IsNumeric(string val, ref double d)
{
    if (val == null)
    {
        return false;
    }
    return Double.TryParse(val, System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out d);
}
 
public bool IsDate(string val)
{
    bool retval = true;
    try
    {
        DateTime dt = Convert.ToDateTime(val, System.Globalization.CultureInfo.InvariantCulture);
    }
    catch (Exception)
    {
        retval = false;
    }
    return retval;
}
Wednesday, February 13, 2008 3:17:24 PM (GMT Standard Time, UTC+00:00) #    Comments [0]  |  Trackback Tracked by:
"http://blastpr.com/wiki/js/pages/viagra/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/prozac/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/clomid/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/hoodia/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/ultram/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/cymbalta/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/accutane/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/celexa/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/claritin/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://morningside.edu/mics/_notes/pages/claritin/index.html" (http://morningsi... [Pingback]
"http://blastpr.com/wiki/js/pages/nexium/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://blastpr.com/wiki/js/pages/prilosec/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://blastpr.com/wiki/js/pages/prozac/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://blastpr.com/wiki/js/pages/zoloft/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/melatonin/index.html" (http://mornings... [Pingback]
"http://morningside.edu/mics/_notes/pages/tramadol/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/rainbow-brite/index.html" (http://morn... [Pingback]
"http://morningside.edu/mics/_notes/pages/paxil/index.html" (http://morningside.... [Pingback]
"http://morningside.edu/mics/_notes/pages/synthroid/index.html" (http://mornings... [Pingback]
"http://morningside.edu/mics/_notes/pages/celebrex/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/wellbutrin/index.html" (http://morning... [Pingback]
"http://blastpr.com/wiki/js/pages/cymbalta/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://blastpr.com/wiki/js/pages/celexa/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://blastpr.com/wiki/js/pages/synthroid/index.html" (http://blastpr.com/wiki... [Pingback]
"http://blastpr.com/wiki/js/pages/celebrex/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://blastpr.com/wiki/js/pages/cialis/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://blastpr.com/wiki/js/pages/wellbutrin/index.html" (http://blastpr.com/wik... [Pingback]
"http://morningside.edu/mics/_notes/pages/ultram/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/lexapro/index.html" (http://morningsid... [Pingback]

 

All content © 2020, Daniel Probert
On this page
This site
Calendar
<January 2020>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678
Archives
Sitemap
Blogroll OPML
Disclaimer

Powered by: newtelligence dasBlog 2.3.12105.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts


Pick a theme: