Skip to content

is there a way to get a result similar to datediff function #7097

Closed
@jiangzhx

Description

@jiangzhx

Is your feature request related to a problem or challenge?

I’d like to ask if there is a way to get a result similar to datediff function , also it seems that this function is not available in DataFusion.

i try another way like this,but how can i get 6 days from interval result

select to_timestamp(now())-to_timestamp('2023-07-20T05:44:00.419557');

+------------------------------------------------------------------------+                                                                                             
| to_timestamp(now()) - to_timestamp(Utf8("2023-07-20T05:44:00.419557")) |                                                                                             
+------------------------------------------------------------------------+                                                                                             
| 0 years 0 mons 6 days 0 hours 51 mins 7.343851000 secs                 |                                                                                             
+------------------------------------------------------------------------+           

Describe the solution you'd like

something like date_diff

Describe alternatives you've considered

add udf like date_diff
or
make
select extract(day from interval '1 days' );
work


Error during planning: No function matches the given name and argument types 'date_part(Utf8, Interval(MonthDayNano))'. You might need to add explicit type casts.
        Candidate functions:
        date_part(Utf8, Date32)
        date_part(Utf8, Date64)
        date_part(Utf8, Timestamp(Second, None))
        date_part(Utf8, Timestamp(Microsecond, None))
        date_part(Utf8, Timestamp(Millisecond, None))
        date_part(Utf8, Timestamp(Nanosecond, None))
        date_part(Utf8, Timestamp(Nanosecond, Some("+00:00")))

Additional context

https://www.postgresql.org/docs/current/functions-datetime.html

https://github.com/apache/arrow-datafusion/blob/52cf58b46133d448e067455baab0faf8a50e565a/datafusion/expr/src/built_in_function.rs#L1021-L1032

https://github.com/apache/arrow-datafusion/blob/52cf58b46133d448e067455baab0faf8a50e565a/datafusion/physical-expr/src/datetime_expressions.rs#L729C1-L729C1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions