Date & Time

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.

  Discussion posts and replies are publicly visible

Parents
  • 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.

  • 0
    Certified Lead Developer
    in reply to eusebiof9911

    Below the code snippet in the language whitespace:

    Could anyone create an Appian plugin to run whitespace code?

Reply Children
No Data