Calculate weeks and days between two dates and automatically update stored cell value
Hi Everyone
I am using an app to calculate weeks and days of pregnancy based on a given last menstrual date and it is working well.
Here is an attachment and the used code:
Dim DateFrom As Date
Dim DateTo As Date
Dim RawDays As Long
Dim Weeks As Long
Dim Days As Long
The Gestational Age stored in MS Access database as for example "34weeks 2days".
My question is how to update this cell value automatically to be "34weeks 5days" after 3 days and so on.
Many thanks
Re: Calculate weeks and days between two dates and automatically update stored cell v
It's a very bad idea to store that string in your database. You should simply store the number of days. You can then display that any way you want to, when you want to, e.g.
Note the use of string interpolation rather than concatenation, improving readability. Note also the use of the If operator rather than the IIf function. That operator has been around for a decade and a half. Never use IIf.
Re: Calculate weeks and days between two dates and automatically update stored cell v
Originally Posted by jmcilhinney
It's a very bad idea to store that string in your database. You should simply store the number of days. You can then display that any way you want to, when you want to, e.g.
Note the use of string interpolation rather than concatenation, improving readability. Note also the use of the If operator rather than the IIf function. That operator has been around for a decade and a half. Never use IIf.
Thanks alot
I agree and appreciate.
Still how to update stored cell value daily?
If Gestational age right now is stored as 25weeks 2days, so how to update it daily in datagridview and database.
For example it must be 26weeks 0day after 5 days from now.
Many thanks
Re: Calculate weeks and days between two dates and automatically update stored cell v
if there is a Table in Access why not use SQL-Query ?
here a query to work the weeks and days from a Date
Code:
SELECT Employees2.FirstName, Employees2.SomeDate, DateDiff("d",[Somedate],Now()) AS CountDays, ([CountDays] Mod 365)\7 AS nWeeks, ([CountDays] Mod 365) Mod 7 AS nDays
FROM Employees2
ORDER BY Employees2.FirstName;
here a Image of the qeury results
the numbers will change as days go on, like JMC said in Post#4
... You should simply store the number of days.....
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
Re: Calculate weeks and days between two dates and automatically update stored cell v
Originally Posted by ChrisE
if there is a Table in Access why not use SQL-Query ?
here a query to work the weeks and days from a Date
Code:
SELECT Employees2.FirstName, Employees2.SomeDate, DateDiff("d",[Somedate],Now()) AS CountDays, ([CountDays] Mod 365)\7 AS nWeeks, ([CountDays] Mod 365) Mod 7 AS nDays
FROM Employees2
ORDER BY Employees2.FirstName;
here a Image of the qeury results
the numbers will change as days go on, like JMC said in Post#4
... You should simply store the number of days.....