Clarity

 View Only
  • 1.  Difference between two dates in mysql

    Posted Jul 01, 2022 07:40 AM
    Hi All - DATEDIFF() is the function used to get the difference of days between two dates, but when i used it in Lookup, it is showing function needs 3 arguments. In the Google results all the examples are on 2 arguments -


    Below is the example.

    SELECT DATEDIFF('2020-10-30', '2020-10-01') AS 'Result';

    I'm using it as - DATEDIFF( INV.SCHEDULE_START , INV.SCHEDULE_FINISH) DAYS

    Please advise.


  • 2.  RE: Difference between two dates in mysql

    Posted Jul 02, 2022 01:55 AM
    Hi

    Clarity does not support mysql. I think, you mean MSSQL and in MSSQL DATEDIFF takes 3 arguments

    https://docs.microsoft.com/en-us/sql/t-sql/functions/datediff-transact-sql?view=sql-server-ver16

    ------------------------------
    Senior Consultant
    ------------------------------



  • 3.  RE: Difference between two dates in mysql

    Posted Jul 03, 2022 10:31 PM
    Hi,

    Add 'result unit' in your example.

    Like below.

    DATEDIFF( INV.SCHEDULE_START , INV.SCHEDULE_FINISH,"Day")

    FUNCTION SYNTAX
    DateDiff(date attribute1,date attribute2, result unit)
    FUNCTION DESCRIPTION
    Returns the number difference between date attribute1 and date attribute2 in the result unit specified (Day, Hour, Minute, or Second).


    ------------------------------
    Regards,
    Ram Babu
    ------------------------------



  • 4.  RE: Difference between two dates in mysql

    Posted Jul 04, 2022 08:55 PM

    Hi Ram - Please help me in Date Formats in MySQL - Im trying to change the Date format from String to Date type.

    I got 2 functions in google results DATE_FORMAT()  and STR_TO_DATE() - but Lookup says both are not in-built functions.

    I have a table "dwh_cmn_period_ln" - it has Period_name - this is date in '05/02/2022' format, i need to change that into Date type '2022-05-02'

    Please advise.




  • 5.  RE: Difference between two dates in mysql

    Posted Jul 06, 2022 06:14 AM
    Hello again,

    As was mentioned above Clarity does not run on MySQL. It runs on MS SQL Server (which is not the same as My SQL), Postgres and Oracle. Have a look here to see what to do in SQL Server:

    https://dba.stackexchange.com/questions/12072/does-sql-server-have-a-date-format-function.

    Paul