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

  • Home
  • SEARCH
  • 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 661545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:16:44+00:00 2026-05-13T23:16:44+00:00

I’m trying to calculate TimeSpans between dates. I have no problem with this if

  • 0

I’m trying to calculate TimeSpans between dates. I have no problem with this if the date is formatted using the native sqlite3 format ‘YYYY-dd-mm’

How would I do this if the date is formatted differently, such as ‘dd-mm-YYYY’

I’ve tried the following with no success.

–Select days between two days; this works if the datetime string is formated YYYY-dd-mm

SELECT julianday(date1) - julianday(date2) AS Span from myTable;

–I tried this for dates in the format of dd-mm-YYYY but it doens’t seem to work
–It seems to be that a date format cannot be specified.

SELECT julianday(strftime('%d-%m-%Y', date1)) - julianday(strftime('%d-%m-%Y', date2)) AS Span from myTable;
  • 1 1 Answer
  • 2 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-05-13T23:16:45+00:00Added an answer on May 13, 2026 at 11:16 pm

    Since you’re using System.Data.SQLite I would recommend using a custom function. This will be easier to use and be consistent with MS SQL Server, making it clearer for other .NET developers to understand and maintain.

    /// <summary>
    /// MS SQL 2005 Compatible DateDiff() function.
    /// </summary>
    /// <remarks>
    /// ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.SQL.v2005.en/tsqlref9/html/eba979f2-1a8d-4cce-9d75-b74f9b519b37.htm
    /// 
    /// 
    /// </remarks>
    [SQLiteFunction(Name = "DateDiff", Arguments = 3, FuncType = FunctionType.Scalar)]
    public class DateDiff : SQLiteFunction
    {
        public override object Invoke(object[] args)
        {
            if (args[0] == DBNull.Value || 
                args[1] == DBNull.Value ||
                args[2] == DBNull.Value)
            {
                return null;
            }
            string part = Convert.ToString(args[0]);
            DateTime startTime = ToDateTime(args[1]);
            DateTime endTime = ToDateTime(args[2]);
    
            switch(part)
            {
                case "year":
                case "yy":
                case "yyyy":
                    return endTime.Year - startTime.Year;
    
                case "quarter":
                case "qq":
                case "q":
                    return (endTime.Year - startTime.Year) * 4 + ((endTime.Month - 1) / 3) - ((startTime.Month - 1) / 3);
    
                case "month":
                case "mm":
                case "m":
                    return (endTime.Year - startTime.Year) * 12 + endTime.Month - startTime.Month;
    
                case "dayofyear":
                case "dy":
                case "y":
                case "day":
                case "dd":
                case "d":
                    return (endTime - startTime).TotalDays;
    
                case "week":
                case "wk":
                case "ww":
                    return (endTime - startTime).TotalDays / 7.0;
    
                case "Hour":
                case "hh":
                case "h":
                    return (endTime - startTime).TotalHours;
    
                case "minute":
                case "mi":
                case "n":
                    return (endTime - startTime).TotalMinutes;
    
                case "second":
                case "ss":
                case "s":
                    return (endTime - startTime).TotalSeconds;
    
                case "millisecond":
                case "ms":
                    return (endTime - startTime).TotalMilliseconds;
    
                default:
                    throw new ArgumentException(String.Format("Date part '{0}' is not recognized.", part));
            }
    
        }
    
        private static DateTime ToDateTime(object source)
        {
            try
            {
                return Convert.ToDateTime(source);              
            } 
            catch (Exception ex)
            {
                throw new ArgumentException(String.Format("DateDiff Input value '{0}' can not be converted to a DateTime.", source), ex);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is

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.