Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8025409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:09:20+00:00 2026-06-04T23:09:20+00:00

XQuery has a set of useful functions for date conversion. But how to convert

  • 0

XQuery has a set of useful functions for date conversion. But how to convert relative dates like “Today” and “Yesterday” into the actual date?

For example “Today, 17:33” should be converted to “2012-05-30”, and “Yesterday, 22:13” to “2012-05-29”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:09:22+00:00Added an answer on June 4, 2026 at 11:09 pm

    1. Parse the Date string

    Parse the date string. I provided a small function which splits the word indicating the date off and parses it. I added some more convenient names for dates, but you can easily add more if neccessary, notice I convert to lower-case! It uses XQuery date and time functions for calculating the matching date.

    declare function local:from-relative-date($string as xs:string) as xs:date {
        switch (lower-case(substring-before($string, ",")))
            case "today"                return current-date()
            case "yesterday"            return current-date() - xs:dayTimeDuration('P1D')
            case "day before yesterday" return current-date() - 2 * xs:dayTimeDuration('P1D')       
            case "tomorrow"             return current-date() + xs:dayTimeDuration('P1D')       
            case "day after tomorrow"   return current-date() + 2 * xs:dayTimeDuration('P1D')       
            default                     return error(xs:QName("XPTY0004"), "Unknown Date")
    };
    

    2. Format the date

    Now use the XQuery 3.0 function format-date(...) (I hope your XQuery engine supports it, BaseX which I used for this example does) to format the date string like you need it:

    format-date(local:from-relative-date("Yesterday, 22:13"), "[Y]-[M00]-[D00]")
    

    If it doesn’t, you will have to use year-from-date(...) and according functions for month and day, use some number formatting and concatenate yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to know whether someone has any experience with XQuery as it is
In xquery, How to get 90 days before date from a given date? Say
I want to use the Saxon-B XQuery class in my ASP.Net website. But my
What would the XQuery look like to check if a node exists, and if
Apparently, BDB-XML has been around since at least 2003 but I only recently stumbled
So I have an XQuery that looks something like this: for $i in /*:rootElement
Say I have a Java String which has xml data like so: String content
Is there any way to perform a LIKE operation with XQuery in the same
I have an XQuery return statement like: return <li> <h3>{ string($TELECAST/title/maintitle) }</h3> <h4>{ string($TELECAST/title/subtitle)
I'm attempting to create an xquery expression that will return selected nodes but will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.