Question DateTime

hasexxl1988

Active Member
Licensed User
Longtime User
Hallo,
ich wollte fragen ob mir jemand Tipps geben kann wie ich ein Programm machen kann um die aktuelle Schwangerschaftswoche auszurechnen anhand des Geburtstermines.
z.b. 20.12.2012 als Geburtstermin, und das das Programm dann anzeigt in welcher Schwangerschaftswoche sich die Person zurzeit befindet.

Hello,
I wanted to ask if someone can give me tips on how I can make a program to calculate the current week of pregnancy using the birth appointment.
e.g. 12/20/2012 as date of birth, and the program then displays at how many weeks the person is present.
 

Mahares

Expert
Licensed User
Longtime User
I hope I understand your question. Below is the code to do the math. You can change the values. Congratulations.

B4X:
'Based on 266 days since conception. You can change the values to do the math or ask your OB/GYN
   Dim DateConcept As String
   Dim WeeksSinceConcept As Float

   DateConcept=DateTime.Date(DateTime.Add(DateTime.dateparse("12/20/2012"),0,0,-266))  '266 days before 
   WeeksSinceConcept=   Round2((DateTime.Now -DateTime.dateparse(DateConcept))/1000/60/60/24/7,2)
   Msgbox("Conception date: " & DateConcept & CRLF _
   & "Expected date of birth: 12/20/2012" & CRLF _
   & WeeksSinceConcept & " Weeks since coneption from today.","CONGRATULATIONS")
 
Upvote 0

hasexxl1988

Active Member
Licensed User
Longtime User
That was very helpful, thank you. But now I know not how I could calculate the day of pregnancy. That it finally looks like this:
Week: 21 day: 5
I'm trying to work with the split function, but since I'm no further, because I do not know the formula and calculate correctly.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Here is the complete code that will break it down in weeks, days, hours, etc.
B4X:
'BELOW TO CALC WEEKS, DAYS, HIURS OF PREGNANCY FROM TODAY.
  'Based on 266 days. You can change the values or ask your OB/GYN
   Dim DateConcept As String
   Dim WeeksSinceConcept As Float
   Dim NWeeks, NDays, Nhours,Nmins,Nsecs As Float
   Dim Weeks, Days,Hours,Mins,Secs As Int
   
   DateConcept=DateTime.Date(DateTime.Add(DateTime.dateparse("12/20/2012"),0,0,-266))  '266 days before 
   WeeksSinceConcept=   (DateTime.Now -DateTime.dateparse(DateConcept))/1000/60/60/24/7
   NWeeks=WeeksSinceConcept
   Weeks=Floor(NWeeks) 
   NDays=(NWeeks-Weeks)*7  :Days=Floor(NDays)
   Nhours=(NDays-Days) * 24  :Hours=Floor(Nhours)
   Nmins=(Nhours-Hours)*60   :Mins=Floor(Nmins)
   Nsecs=(Nmins-Mins)*60        :Secs=Floor(Nsecs)
   Msgbox("Conception date: " & DateConcept & CRLF _
   & "Expected date of birth: 12/20/2012" & CRLF _
   & "Time since conception: " & Weeks & " Weeks "  & Days & " days " & Hours & " hrs " & Mins & " min " & Secs & " sec","CONGRATULATIONS")
 
Upvote 0
Top