Skip to main content
September 11, 2023
Question

Date & Time

  • September 11, 2023
  • 3 replies
  • 1 view

Hello,

I need to pass the yesterday's date and a specific time to a variable of dateTime type. Basically today I want to get all the data which is saved in database yesterday. How to achieve this?

Thank you.

    3 replies

    mathieud0001
    Brainy
    September 11, 2023

    Hi,

    I provided answers to 2 previous threads of yours which show how to create filters and calculate datetimes.

    Filter for previous month: [View:https://community.appian.com/discussions/f/general/29915/to-find-if-a-given-date-is-from-previous-month]

    Filter for last 45 days: [View:https://community.appian.com/discussions/f/user-interface/29941/how-to-generate-report-based-on-the-user-filters]

    Would be very similar to the 45 day answer, except you subtract 1 day instead of 45 and pass 00:00 in the hours/minutes/seconds fields of the startDateTime and 23:59:59 in the endDateTime.

    If an answer helps you, please mark it as verified so that others can find it later.

    December 19, 2023

    To get yesterday’s date in Python, you can use the datetime module and the timedelta() function. Here’s an example code snippet that shows how to get yesterday’s date in the format MMDDYY:

    Python
    from datetime import date, timedelta
    
    yesterday = date.today() - timedelta(days=1)
    yesterday_date = yesterday.strftime('%m%d%y')

    In this code snippet, date.today() returns today’s date, and timedelta(days=1) subtracts one day from it, giving us yesterday’s date. The strftime() function is then used to format the date as MMDDYY. seterra

    To get a specific time for yesterday’s date, you can use the datetime module and the combine() function. Here’s an example code snippet that shows how to combine yesterday’s date with a specific time:

    Python

    from datetime import datetime, timedelta
    
    yesterday = datetime.now() - timedelta(days=1)
    specific_time = datetime.strptime('12:30:00', '%H:%M:%S').time()
    yesterday_specific_time = datetime.combine(yesterday.date(), specific_time)

    In this code snippet, datetime.now() returns the current date and time, and timedelta(days=1) subtracts one day from it, giving us yesterday’s date and time. The strptime() function is then used to parse the specific time string 12:30:00 into a time object. Finally, the combine() function is used to combine yesterday’s date with the specific time.

    stefanhelzle0001
    Brainy
    December 19, 2023

    Below the code snippet in the language whitespace:

                                                                        

    Could anyone create an Appian plugin to run whitespace code?