Comparing dates in Lingo - datetime

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.

Related

Why does strptime() append a time value even when not specified?

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']:

Getting invalid date from moment.js?

I have a redis stored timestamp when I get it, it looks like this:
1454803149444
Then when I try to do:
i.text-muted.createdAtPost= moment(post.timestamp).format("MM/DD/YY # h:mm:ss") // Jade Template
I get
Invalid Date
But if I take the same integer, and go moment(1454803149444).format(h:mm:ss") I get 05/21/54 # 12:00:00
Any information would be great thanks.
I had the same problem. What I did was
let time = post.timestamp / 1000;
let formatted = moment.unix(time).format("MM/DD/YY # h:mm:ss");
I have no idea why this works. I tried forcing the value into an integer and still got invalid date. I hard coded the value that was console logged and it worked, like in your case. For some reason dividing it by 1000 and calling it a unix timestamp works fine. Seems like a bug to me.
What value does timestamp pass?
Did you check that?
If it has a specific format you need to set it as:
moment(post.timestamp, 'YYYY/DD/MM').format("MM/DD/YY # h:mm:ss")

Converting Date to CurrentCompany timeZone in Dynamics ax x++

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.

convert to date and extract only the time

How could I get only time of a varchar2? I do:
select to_date(substr(fecha,10,16),'HH:MI:SS AM') from total;
But it gives me:
01/06/2014 5:50:01
01/06/2014 5:50:05
01/06/2014 5:50:05
01/06/2014 5:50:50
And I would like to have:
5:50:01
5:50:05
5:50:05
5:50:50
Any help? Please
Although it may not be what you expected, the code is working correctly. In Oracle, if you don't specify the day-month-year portion of a date it defaults to the first day of the current month. An Oracle DATE must always have a day/month/year - there's no way to have a time without a date in a DATE column or variable.
SQLFiddle here.
If you really want to have it display only the time portion of the date you'll just have to extract only the hours-minutes-seconds using TO_CHAR(date_value, 'HH24:MI:SS') and treat it as a character string.
Share and enjoy.
i think you should use both, to_char and to_date:
select to_char(to_date(fecha,'dd-mm-yyyy HH:MI:SS AM'),'HH:MI:SS AM')
time from total;

How can I get a file's last modified time in asp.net?

I need to find the time when the file was last modified in a day.
Using the below code I only get the date:
System.IO.File.GetLastWriteTime(Server.MapPath("myFile.txt")).ToString("D");
How to get only the time part?
Use HH, mm, ss:
System.IO.File.GetLastWriteTime(Server.MapPath("myFile.txt")).ToString("HH:mm:ss");
May be this will help:
System.IO.File.GetLastWriteTime(#"C:\MyPath\a.txt").TimeOfDay.ToString()
I go this:
17:55:14.3229896
You can format as per your convenience

Resources