Created
November 15, 2012 07:27
-
-
Save linjunpop/4077199 to your computer and use it in GitHub Desktop.
Convert 'Wednesday, October 10, 2012' to '20121010'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| declare function local:format-date($date as xs:string) | |
| { | |
| format-date( | |
| local:string-to-date(substring-after($date, ", ")), | |
| "[Y][M][D]" | |
| ) | |
| }; | |
| declare function local:string-to-date($date as xs:string) as xs:date | |
| { | |
| let $month-name := substring-before($date, " ") | |
| let $day := substring-before(substring-after($date, " "), ",") | |
| let $year := substring-after($date, ", ") | |
| let $month := local:month-name-to-number($month-name) | |
| return xs:date(concat($year, "-", $month, "-", $day)) | |
| }; | |
| declare function local:month-name-to-number($month-name as xs:string) | |
| { | |
| switch($month-name) | |
| case "January" return "01" | |
| case "February" return "02" | |
| case "March" return "03" | |
| case "April" return "04" | |
| case "May" return "05" | |
| case "June" return "06" | |
| case "July" return "07" | |
| case "August" return "08" | |
| case "September" return "09" | |
| case "October" return "10" | |
| case "November" return "11" | |
| case "December" return "12" | |
| default return error(xs:QName("FOO"), "Wrong Month name") | |
| }; | |
| local:format-date("Wednesday, October 10, 2012") (: output: 20121010 :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment