I have the following Python code:
print ('2020-02-09')
print(datetime.datetime.strptime('2020-02-09'], '%Y-%m-%d'))
which yields
2020-02-09
2020-02-09 00:00:00
Is there a better choice of functions which does not return the number of seconds? IOW, how can I compare the two values without having the time component evaluated? E.G.:
if datetime.datetime.today().date() == datetime.datetime.strptime('2020-02-09'], '%Y-%m-%d'):
For clarification, my goal is to store the date (no time value) as an attribute in a JSON file and then during runtime compare it to datetime.now().date() or datetime.today().date().
What about:
from datetime import datetime as dt
if dt.today().date() == dt.strptime('2020-02-09', '%Y-%m-%d').date():
Note the inclusion of the .date() trailing the second operand.
You can just compare the date part of both the function:
just add date() at the end of
datetime.datetime.strptime('2020-02-09', '%Y-%m-%d').date()
I was overthinking this too much and also missing the ability to chain .date() to the function. Thank you for clarifying that for me.
Here is what I decided to go with:
#example date for JSON attribute
data['lastWritten'] = '2020-02-09'
if str(datetime.datetime.today().date()) == data['lastWritten']:
Related
My preceding module in Integromat gives me an expiration date in UNIX time, which is 1640930400.
When I use the FormatDate function to convert this, I'm getting 12/31/1969 when I was expecting to get 12/31/2021. I can't seem to figure out what I'm doing wrong here. Any help would be much appreciated.
Use this instead to first parse the date and then apply the desired formatting to get the results that you want,
{{formatDate(parseDate(1.date; "X"); "MM/DD/YYYY")}}
Based on the structure of the data, I could not import the data by defining the types prior to upload/import.
So, doing that won't work. Anyway, it comes out as a number, below for examples:
43683
43686
43689
I did try some methods. Below is the code I did use and it did sort of end up turning it into a date but the year is wrong (comes out 2089 instead of 2019). I did do trimws prior to the below.
Transactions_Combined$Trans_Date <- as.numeric(Transactions_Comvined$Trans_Date)
Transaction_Combined <- as.Date(Transactions_Combined$Trans_Date)
Comes out as:
'2089-08-07'
'2089-08-10'
'2089-08-13'
Just want an accurate date and make sure I'm doing it right too. Thanks for your help!
Use the function readxl::read_excel() from the readxl-package to read in your excel-data.
Set the col_types-argument to "Date", and it will read the excel-dates to POSIXct-timestamp.
If this is not an option, you can try
as.POSIXct( colum_with_excel_times * 24 * 3600 + as.POSIXct( "1899-12-30 00:00" ) )
Another option could be janitor::excel_numeric_to_date()
I'm trying to convert a datetime that looks like this: 2017-09-19T07:00:00-07:00 into EST, but i keep getting Null values when using the hive built in UTC conversion.
I've tried using a regular expression to parse the date:
date_format(from_unixtime(unix_timestamp(2017-09-19T07:00:00-07:00, "yyyy-MM-dd'T'HH:mm:ss")
- (cast(regexp_extract(regexp_extract(2017-09-19T07:00:00-07:00, '(-[0-9][0-9]:[0-9][0-9])$', 1),'(-[0-9][0-9])',1) as int)*3600) -18000),'YYYY-MM-dd HH:mm')
but that's not good, since there's an hourly difference based on the time of year.
I've also tried:
FROM_UTC_TIMESTAMP(UNIX_TIMESTAMP(2017-09-19T07:00:00-07:00, "yyyy-MM-dd'T'hh:mm:ss:SSS'ZZZZZ'") * 1000, 'EST')
and
FROM_UTC_TIMESTAMP(UNIX_TIMESTAMP(2017-09-19T07:00:00-07:00, "yyyy-MM-dd'T'hh:mm:ss:SSS'Z'") * 1000, 'EST')
but that appears to not work either. What am I doing wrong?
I think that this method needs the date as a string like this:
date_format(from_unixtime(unix_timestamp('2017-09-19T07:00:00-07:00', "yyyy-MM-dd'T'HH:mm:ss")
Normally, the date formats are for strings, not for integers or numbers.
I found the answer on my own by combining the two ways of running the query.
date_format(
FROM_UTC_TIMESTAMP(
(unix_timestamp('2017-09-19T07:00:00-07:00', "yyyy-MM-dd'T'HH:mm:ss")
+ (cast(
regexp_extract(
regexp_extract('2017-09-19T07:00:00-07:00', '(-[0-9][0-9]:[0-9][0-9])$',1),'(-[0-9][0-9])',1) as int)
*-3600)
)*1000 ,'America/New York')
,'YYYY-MM-dd HH:mm:ss')
You are getting NULL because the pattern (format of the date and time) you have provided is not matching with the actual date time value. Correcting the date time format in your query would resolve this issue:
select from_unixtime(UNIX_TIMESTAMP("2017-09-19T07:00:00-07:00", "yyyy-MM-dd'T'HH:mm:ssXXX"), "yyyy-MM-dd HH:mm:ss");
Check out this link to know more about the date time patterns: https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
I have a scenario where i need to convert a Datefield(joindate) to currentcompany timezone date. And then i need to compare this with anotherdate(startdate). If the difference is more than 365 days i need to give an warning. Can someone help me in this.
Thanks in advance.
You can apply a timezone to an utcdatetime via DateTimeUtil::applyTimeZoneOffset
The company timezone can be retrieved by calling DateTimeUtil::getCompanyTimeZone
Afterwards calculate the difference by calling DateTimeUtil::getDifference, which returns the difference in seconds so you have to compare that with the seconds per year.
To avoid inserting a 'magic' number, use the constants in the macro library TimeConstants.
If Datefield(joindate) is of type date and not utcDateTime then DateTimeUtil::newDateTime() should be used to convert it to utcDateTime:
utcDateTime joinDateTime = DateTimeUtil::newDateTime(joindate, 0,
DateTimeUtil::getCompanyTimeZone());
DateTimeUtil::getDifference() can be used to get the number of seconds between the utcDateTime values.
If both Datefield(joindate) and anotherdate(startdate) are of type date and not utcDateType then no conversion is required at all, and you can check whether the difference is more than 365 as follows:
if (joindate - startdate > 365) {}
If the above assumptions are wrong, see DAXaholic's answer.
How do I compare two dates in Lingo? To be specific, I want to know if today's date is after some fixed date. I know I can create the fixed date by using:
date("20090101")
and I can get the current date using:
_system.date()
but I can't seem to directly compare the two. Do I have to parse the _system.date() to determine if it's after my fixed date? I tried:
if(_system.date() > date("20090101") then
--do something
end if
but that doesn't seem to work. Any ideas?
Instead of _system.date(), try _movie.systemDate(), it will return a date object that you can safely compare with another one.
if _movie.systemDate() > date("20090101") then
--do something
end if
regards
I ended up doing the following. Inelegant, but it works:
if (_system.date().char[1..2] >= 01 and _system.date().char[4..5] >= 01 and _system.date().char[7..10] >= 2010) then
alert("Your license has expired. Please contact the Company to renew your license.")
_player.quit()
end if
It does the trick, but I would still be interested in alternative methods of doing this.