calulate according to the DOB given - ruby

I made student list containing roll no.,name, gender, DOB,Age ,marks1,marks2,marks3,total and avg.
i want to right a code for age
that is when i click on age it should display the correct age according to the DOB given.
can you help using textbox events in c#

The algorithm should be
ageInYears = currentYear - birthYear - (birthMonth <= currentMonth && birthDay <= currentDay ? 0 : 1);
Subtract the years, and subtract an additional year if they haven't had their birthday yet this year.

Related

Get Data of a month from a dated column

Respected all I want to bring data from a dated column with input of a Month like I have a column in database which type is dated but I want data only mentioning just month and year I tried but got errors please check my query
SELECT
M.INV_NUM, M.GD_NUM, M.INV_DATE, M.QTY1,
D.ITEM_CODE, D.HS_CODE, R.QNTY, R.waste_per,
R.WASTE_QNTY, (R.WASTE_QNTY+R.QNTY) TOTAL_CONSUMED
FROM
DOCT_EXPT_SALE_MST M,
DOCT_EXPT_SALE_RAW R,
DOCT_EXPT_SALE_DTL D
WHERE
R.SALE_DET_ID = D.SALE_DET_ID
AND D.SALE_ID = M.SALE_ID
AND M.INV_DATE BETWEEN TO_DATE(TRUNC('072022','MMYYYY')) AND TO_DATE(TRUNC('072022','MMYYYY'))--TO_NUMBER(TO_DATE(TO_CHAR('01072022','DDMMYYYY'))) AND TO_NUMBER(TO_DATE(TO_CHAR('31072022','DDMMYYYY')))
AND M.COMP_CODE = 3;
I tried many things but all is gone in vain. If anybody help me on this, I shall be very thankful my database is 11g
If you are being passed the string '072022' then you can do:
AND M.INV_DATE >= TO_DATE('072022','MMYYYY')
AND M.INV_DATE < ADD_MONTHS(TO_DATE('072022','MMYYYY'), 1)
The TO_DATE('072022','MMYYYY') clause will give you midnight on the first day of that month, so 2022-07-01 00:00:00.
The ADD_MONTHS(TO_DATE('072022','MMYYYY'), 1) clause will take that date and add one month, giving 2022-08-01 00:00:00.
The two comparisons will then find all dates in your column which are greater than or equal to 2022-07-01 00:00:00, and less that 2022-08-01 00:00:00 - which is all possible dates and times during that month.
So your query would be (switching to ANSI joins!):
SELECT
M.INV_NUM, M.GD_NUM, M.INV_DATE, M.QTY1,
D.ITEM_CODE, D.HS_CODE, R.QNTY, R.waste_per,
R.WASTE_QNTY, (R.WASTE_QNTY+R.QNTY) TOTAL_CONSUMED
FROM
DOCT_EXPT_SALE_MST M
JOIN
DOCT_EXPT_SALE_DTL D ON D.SALE_ID = M.SALE_ID
JOIN
DOCT_EXPT_SALE_RAW R ON R.SALE_DET_ID = D.SALE_DET_ID
WHERE
M.INV_DATE >= TO_DATE('072022','MMYYYY')
AND M.INV_DATE < ADD_MONTHS(TO_DATE('072022','MMYYYY'), 1)
AND M.COMP_CODE = 3;

Ruby - How many days?

I need to calculate how many days lived on earth based on three parameters : day, month and year.
I don't know how to convert the input onto a date; and then how to convert the date onto number of days.
This is my code for the moment...
require 'date'
def age_in_days(day, month, year)
lived = (day+"-"+month+"-"+year).to_s
date_lived Date.parse(lived)
return (Date.today - date_lived).to_i
end
You can create a Date object directly with:
Date.new(year, month, day)
There's no need to convert it to a string and parse. Parsing could also be dangerous. Is 1982-04-02 the 4th of February or 2nd of April?
You cannot add a number and string like this, BTW. Should 1 + '2' be '12' or 3? Ruby cannot decide for you so you need to explicitly convert integers to string.
day.to_s + "-" + month.to_s + "-" + year.to_s
or simply
[day, month, year].join('-')
But you don't need it anyway:
require 'date'
def age_in_days(day, month, year)
birthdate = Date.new(year, month, day)
(Date.today - birthdate).to_i
end

Vue js & validate DOB is within a range?

Using Vue js and v-validate how can I determine if the date of birth is greater than 21 and less then 55 years old? Any help is greatly appreciated.
import * as moment from "moment";
let birthday = moment(moment.now()).diff(moment(this.user.day + this.user.month + this.user.year, "DD.MM.YYYY"),"years");
if(birthday > 21 && birthday < 55) {
// do next steps
}
Moment(npm install moment) is used to parse, manipulate & display dates and times in JavaScript. moment.now() will give the present date and assuming you have three fields for day, month and year in different variables, format it and use the diff function to find the age.
The example from Madhuri works for me but i change the input as hard coded string.
enter code here let birthday = moment(moment.now()).diff(moment('01.01.1990', "DD.MM.YYYY"), "years");
if(birthday >= 20 && birthday <=70 ){
return birthday;
}
}
I solved it with with value from form input which works for me.
checkBirthday(){
const birthDayDate = document.getElementById("birthdate").value;
const age = moment().diff(birthDayDate, "years");
// let birthday = moment(moment.now()).diff(moment('01.01.1990', "DD.MM.YYYY"), "years");
if(age >= 18 && age <=74 ){
return age;
}
},

Get what date it is based on week number and day number asp classic?

I need to know what date it is based on a week number and a day number.
So if I have weeknr=3 and day=1(for today- sunday) and lets say the year=2016 how can I make this into 2016-01-24.
Any input really appreciated, thanks.
Your best help will be the DatePart function (see here for docs). It's not altogether straightforward, because there are options to consider like "first day of week" and "first week of year", but you can define those in DatePart.
This would be my solution:
option explicit
function getDateByWeek(year, week, day)
dim dt, woy, add_days
dt = DateSerial(year, 1, 1)
do
woy = DatePart("ww", dt, vbSunday, vbFirstFullWeek)
' possibly change options [,firstdayofweek[,firstweekofyear]]
dt = DateAdd("d", 1, dt)
loop while woy<>1
add_days = week * 7 + day - 2
' -1 because we already added one day extra in the loop
' -1 to correct given day (sunday = 1)
getDateByWeek = DateAdd("d", add_days, dt)
end function
Response.Write "RESULT: " & getDateByWeek(2016, 3, 1) ' -> 24.01.2016
I start by finding the first day of the first week in a loop and then adding the cumulative amount of days to have a result.
Well the best way is to work out what the week start of the year is and take it from there.
Firstly, the first Thursday of any year is always in the first week of the year, so a simple calculation of adding the correct number onto the 1st January is obvious. After this we simply mulitply out the weeks and add the days:
Const C_THURSDAY = 5
Function GetDateFromYWD(y, w, d)
Dim tDate, aDate
'Get the first of the year...
tDate = DateSerial(y, 1, 1)
'Workout the start of the first week in the year...
aDate = tDate + Int(WeekDay(tDate)>C_THURSDAY And 7) - WeekDay(tDate)
'Add on the number of weeks plus days we're looking for...
aDate = aDate + (w * 7) + d
GetDateFromYWD = aDate
End Function

Calculating holidays

A number of holidays move around from year to year. For example, in Canada Victoria day (aka the May two-four weekend) is the Monday before May 25th, or Thanksgiving is the 2nd Monday of October (in Canada).
I've been using variations on this Linq query to get the date of a holiday for a given year:
var year = 2011;
var month = 10;
var dow = DayOfWeek.Monday;
var instance = 2;
var day = (from d in Enumerable.Range(1,DateTime.DaysInMonth(year,month))
let sample = new DateTime(year,month,d)
where sample.DayOfWeek == dow
select sample).Skip(instance-1).Take(1);
While this works, and is easy enough to understand, I can imagine there is a more elegant way of making this calculation versus this brute force approach.
Of course this doesn't touch on holidays such as Easter and the many other lunar based dates.
And it gets complicated if you have to consider non-christian holidays. For example, jewish holidays are based on the jewish calender..
Maybe not so elegant, but more error prone - you can just add a table of all relevant holidays for the next 100 years.
int margin = (int)dow - (int)new DateTime(year, month, 1).DayOfWeek;
if (margin < 0) margin = 7 + margin;
int dayOfMonth = margin + 7*(instance - 1) //this is for 0-based day number, add 1 if you need 1-based. instance is considered to be 1-based
Please note that I wrote it without trying to compile, so it is to give the idea, but may require some clean up. Hope this helps!

Resources