I'm using fullcalendar-scheduler and trying to get the current month and year whenever the user selects a new date view. For example, whenever the user selects a previous/next month, or week, or day, I need a trigger to update some things.
What I have is close, but it gives me the wrong month:
datesSet: function(info) {
var y = info.view.currentStart.getFullYear();
var m = info.view.currentStart.getMonth();
alert('year = ' + y + ' month = ' + m);
}
It looks like dateSet is triggered when the date changes (which is good) but currentStart.getMonth seems to always give me a number that is not the current month. It is always giving me the current month minus one (I think).
Before I happily go adding 1 to the month it gives me, I'd like to know if I'm doing it wrong. Or, if I'm doing it correctly and the index is simply zero = January instead of 1 = January.
Related
In the interpretation window I want to print the date of the bar that follows say 10 bars after the selected bar. Let's assume I have selected Monday, the third of September 2018. Then Amibroker should print "2018-09-17" (10 trading days later). First I tried:
if (Status("action") == actionCommentary)
{
printf(DateTimeToStr(DateTimeAdd(SelectedValue(DateTime()), 10, inDaily)));
}
However, this simply adds 10 days to the calendar date and hence prints "2018-09-13". Another approch would be to use the bar index:
printf("%.0f", SelectedValue(BarIndex() + 10));
But how to convert a bar index to a date?
Maybe try valuewhen
newDate = ValueWhen(SelectedValue(BarIndex() + 10), DateTimeToStr(DateTime()));
Amibroker Help - Valuewhen
I am new to progress and I want to calculate age from the date of birth and I have no idea how to do it. If anyone knows about this please help me.
Thanks in advance.
What I have tried so far is:
define var dob as date.
define var age as character.
assign
dob = 09/16/1988.
age = STRING(INT(YEAR(TODAY) - YEAR(dob ))).
message age view-as alert-box.
it show age 30 but in real the age is 29.
Use the interval function.
define var dob as date initial 09/16/1988.
message interval( today, dob, "years" ) view-as alert-box.
Returns 29 (as long as today is before the 16th of this year) - handles leap years fine too.
In your code you are just count years, that is not the correct way. It will be shown just difference of the year. You need to count years based on month and days also. So, you can try the following code that will work also for the leap year.
define var dob as date.
define var vYears as int.
define var age as int.
assign
dob = 09/16/1988.
vYears = int(year(today) - year(dob)).
if (month(today) < month(dob)) then do:
age = vYears - 1.
end.
if (month(today) = month(dob)) then do:
if (day(today) < day(dob)) then do:
age = vYears - 1.
end.
else do:
age = vYears.
end.
end.
if (month(today) > month(dob)) then do:
age = vYears.
end.
message age view-as alert-box.
Something you can do in ABL is to subtract dates. which gives the age in days. You could then divide that by 365 and round it down to give the age in years. Obviously this doesn't take leap years into account, so isn't 100% accurate.
DEFINE VARIABLE dob AS date.
DEFINE VARIABLE age AS INTEGER.
ASSIGN
dob = 09/16/1988
age = TRUNCATE(((TODAY - 03/25/1979) / 365),0).
MESSAGE age VIEW-AS ALERT-BOX.
Alternatively, if you want it to be accurate including leap years you have to work a bit harder.
What I've done here is to add the number of years to the birth date to see if the birthday has already happened. If it hasn't then I take 1 year away. There's probably more elegant solutions, but it will do the job!
DEFINE VARIABLE dob AS date.
DEFINE VARIABLE age AS INTEGER.
DEFINE VARIABLE comp AS DATE NO-UNDO.
ASSIGN
dob = 09/16/1988.
comp = add-interval(dob,year(TODAY) - year(dob),"YEARS").
IF TODAY GT comp THEN
age = year(TODAY) - year(dob).
ELSE
age = year(TODAY) - year(dob) - 1.
MESSAGE age VIEW-AS ALERT-BOX.
I am new in this library. I have 2 dates, and I would like to obtain the difference in days, minutes and hours between both. but for some reason the output is an erroneous data. I have based on this page
to get the exact difference and it is different to my result. what am I doing wrong?
var now=2018-07-04 00:37:02;
var then=2018-07-05 08:00:00;
moment.utc(moment(now,"YYYY/MM/DD HH:mm:ss").diff(moment(then,"YYYY/MM/DD
HH:mm:ss"))).format("HH:mm:ss");
output is : 16:37
There are two significant problems here:
a.diff(b) returns a - b, so it will be positive if a is later than b. You're using now.diff(then) effectively, so that will currently give a negative difference, and I suspect you're expecting it to be positive.
You're turning a duration in time into a date/time using moment.utc. The value just isn't a date/time, so shouldn't be treated as one. Instead, use moment.duration(...) to convert to a momentjs Duration object, which you can then handle however you want.
Here's a complete example, having broken out each of the conversions involved for readability:
var now = "2018-07-04 00:37:02";
var then = "2018-07-05 08:00:00";
var parsedNow = moment(now, "YYYY/MM/DD HH:mm:ss");
var parsedThen = moment(then, "YYYY/MM/DD HH:mm:ss");
var diff = parsedThen.diff(parsedNow);
var durationDiff = moment.duration(diff);
alert(durationDiff.toISOString());
Output: PT31H22M58S
That 31 hours is 1 day + 7 hours etc. While a duration has the concept of days, months, years etc, I don't see any way of normalizing a duration created from diff to "1 day 7 hours". (It could certainly be done, but only as far as days - you couldn't normalize to include months without providing more context.)
I am using an ASP calendar to show a list of dates, however the way the calendar overlaps and may show the last few dates of March, with the entire month of April, with the first few days of may(please see images below) is causing a problem.
I have set the 'startDate' and 'endDate' to be the start and end of that month. So if the user clicks 10th April, it will show all the stored dates btn 1st april to the 30th april. I need to change this to include the month b4 and the month after, SO any date in april will include all of March, April and May.
'Green is the date selected by the user, red is todays date, and blue are the stored dates in the DB table.'
DateTime startOfMonth = new DateTime(DiaryDate.Year, DiaryDate.Month, 1);
DateTime endOfMonth = startOfMonth.AddMonths(1).AddDays(-1);
The above code selects the first and last date of each month (of the chosen date)
I want to select the entire previous current and next month
not sure on the correct syntax. any help appreciated?
Try this:
// First, get the dates a month before - and after - the specified date.
DateTime nextMonth = DiaryDate.AddMonths(1);
DateTime lastMonth = DiaryDate.AddMonths(-1);
// Get the last day of next month.
DateTime endOfNextMonth = new DateTime(nextMonth.Year, nextMonth.Month,
DateTime.DaysInMonth(nextMonth.Year, nextMonth.Month));
// Get the first day of last month.
DateTime startOfLastMonth = new DateTime(lastMonth.Year, lastMonth.Month, 1);
Now you can simply use endOfNextMonth and startOfLastMonth as your "boundary" dates, as you are currently doing with startOfMonth and endOfMonth.
I have seen a lot of info on how to subtract one datetime from the other and how to add years on to a datetime. but the following is giving me a headache....
When a user inserts a record a hidden field called subdate with a value of datetime.now is added to the db.
I then need to have an 'old records' page that lists all the entries that are over 1 year old and was hoping to use something (but using subtract method) similar to;
(DateTime.Now.AddYears(1))
but there is no SubtractYears available? Why?
Please can you let me know how I achieve the same result?
DateTime.Now.AddYears(-1)
From the documentation:
A number of years. The value parameter can be negative or positive.
now = datetime.now()
last_year = (now.year - 1)
datestr = (datetime.strptime(str(now.year - 1), "%Y")).strftime("%y")
print(f"Last Year: {datestr}")
The output will be:
Last Year: 20
If you prefer to have four digit year then change %y to %Y