473,326 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

C# - convert 'days old' to date of birth

(C#)

Hi,

I need to convert how many 'days Old' someone is (e.g. 3 years old = 1,095 days old) to a 'date of birth' answer i.e. dd/MM/yyyy. I have tried many different ways how to do this, but to no avail (yet) - e.g. using a mathematical formula but it gets a bit complicated, especially when considering how to implement that into C# (for a beginner, at least).

What is in the box below is one of the many ways I have tried thus far. I know it's wrong but it's one of many of my attempts. What is the simplest way to go about this (assuming 1 year is 365 days, if the computer doesn't have it's own automated calculation to include leap years)?

Expand|Select|Wrap|Line Numbers
  1.  
  2. public static string GetBirthDate(int daysOld)
  3.         {
  4.             var dateToday = Convert.ToInt32(DateTime.Now);
  5.  
  6.             var calc = (dateToday - 365.25 * daysOld);
  7.  
  8.             return Convert.ToString(calc);
  9.         }
  10.  
  11.  
Finally, if I am to include leap years, would the adjustment to simply be to take into consideration that 1 year = 365.25 years? Or would there be more complexity to this?

Kind regards.
Jul 14 '17 #1
2 1285
Luk3r
300 256MB
This would be the easiest way in my opinion:
Expand|Select|Wrap|Line Numbers
  1. DateTime birthDate = DateTime.Now.AddDays(-1095);
Jul 17 '17 #2
this doesn't seem to work
Jul 17 '17 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Num | last post by:
Hi all, I have to convert a J2EE date as a long ("Millis") in a .NET date as a long ("Ticks") In Java, currentTimeMillis, is the difference, measured in milliseconds, between the current time...
7
by: Nimmy | last post by:
Hi, I have a file which has different dates, I want to scanf them as CHAR and convert them to DATE format, how can I do this? Thanks
0
by: stevag | last post by:
I want to convert a custom date format of the type DD/MM/YYYY into the RFC 822 date format in order to use it for RSS feeds. I want to do this transformation into an XSLT transformation which is...
9
by: mistral | last post by:
Need help to remove list of days from date script. Need format "June 07, 2006" <SCRIPT LANGUAGE="JavaScript"> <!-- Begin // Get today's current date. var now = new Date();
1
by: jimmybaba | last post by:
hi all i am newly graduate and started my first job.......i am geting problem to convert datetime into date only , i am trying to get values from sqlserver table with comparison of date. i am using...
3
by: jaeden99 | last post by:
I was wandering if nyone has a script to move files older than x days old? i've seen several to delete, but I don't want to delete. I would like to create a backup of the files first verify with...
2
by: iffizin | last post by:
how to convert character to date. writetime is character data type. i want to have CPU utilization of last 24 hrs. for time being i want to have result from 1 server. select...
5
by: Artie | last post by:
Hi, I have a date field stored as an INT and need to convert to a date format mm/dd/yyyy. I'm having trouble determining what the starting date is. min(date) = 730395 max(date) = 733189 ...
6
by: nady | last post by:
Hi, I have a database in mysql i have column which is text and i need to convert it to date for query purposes. the format for the string in the column is dd/mm/yyyy i need to convert this to...
5
satiss7pwr
by: satiss7pwr | last post by:
I have a string date like this: "3/28/2008 12:05:45 pm" i want to convert it into date and display the out put any one can help me plssssssssss
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.