473,792 Members | 3,042 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculate the date after subtracting nmbr of days form a date

Hi,

I'm currently adding a new module to an old borland C3.1 application
(dos).
And I need to calculate a date by subtracting the number of days from
a given date.

I know I could use an array of days in the months and go back by
leaping when 1 is reached. (keeping the 29the of feb and january/year
in mind).
But is there no function in Borland C3.1 which will do this for me?

I couldn't find one in the help?

Regards
Laery
Nov 14 '05 #1
11 6478
th******@hotpop .com (Laery) wrote in
news:c6******** *************** ***@posting.goo gle.com:
I'm currently adding a new module to an old borland C3.1 application
(dos).
And I need to calculate a date by subtracting the number of days from
a given date.
[...]
I couldn't find one in the help?


Look-up difftime and localtime... They're functions that have been in the
Borland libraries at least since v1.5 and should help you do what you're
trying to do.
John
Nov 14 '05 #2
Laery wrote:

Hi,

I'm currently adding a new module to an old borland C3.1 application
(dos).
And I need to calculate a date by subtracting the number of days from
a given date.


Load the date into a struct tm, taking care to ensure that:

(a) all fields you don't set are cleared to 0, eg with:
struct tm date = (0); /* for now, just trust me on this */
(b) the year field contains the full year less 1900 (so, for 2005,
it would be set to 105).
(c) the month field is in the range 0 to 11.
(d) all other relevant fields are set correctly.

Now subtract the number of days you want, and then pass the
struct's address to mktime(), catching the result in a time_t
object.

If the result is not (time_t)-1 (which would indicate failure to
convert the date as you require), it can be passed to localtime()
or gmtime(), which both return pointers to struct tm from which
you can extract the date information you require.
Nov 14 '05 #3
John <oz***@ozbus.ne t.au> wrote:
th******@hotpop .com (Laery) wrote in
news:c6******** *************** ***@posting.goo gle.com:
I'm currently adding a new module to an old borland C3.1 application (dos).
And I need to calculate a date by subtracting the number of days from
a given date.

I couldn't find one in the help?


Look-up difftime and localtime... They're functions that have been in the
Borland libraries at least since v1.5 and should help you do what you're
trying to do.


No, they won't. difftime() gives the difference, in seconds, between two
time_t's; it doesn't allow you to change an existing time_t. localtime()
converts from time_t to struct tm, but doesn't do any other
computations.
Using mktime() is the right solution. If BC3.1 doesn't have it yet
(i.e., if it's pre-ISO), you _may_ be able to get away with subtracting
days*24*3600 from a time_t, but do note that this relies on time_t being
a straight number of seconds since the epoch, which it isn't required to
be. Doing so would make your code unportable, but if it's already
Borland-specific, that may not be a problem. Adding a comment explaining
the hack would be a good idea, even so.

Richard
Nov 14 '05 #4
Laery wrote:
Hi,

I'm currently adding a new module to an old borland C3.1 application
(dos).
And I need to calculate a date by subtracting the number of days from
a given date.

I know I could use an array of days in the months and go back by
leaping when 1 is reached. (keeping the 29the of feb and january/year
in mind).
But is there no function in Borland C3.1 which will do this for me?

I couldn't find one in the help?

Regards
Laery


I have a really robust date library which was published in the C User's
Journal a few years ago. Drop me a line and I will email it to you
(damn, I've got to get that web page up!). I also used it to write a
Unix shell utility called ADU (a date utility) that allows you to do
date math in the Unix shell. If there were a decent shell for Windows
you could use it there too.
Nov 14 '05 #5
On Thu, 24 Feb 2005 11:04:15 +0000 (UTC), infobahn
<in******@btint ernet.com> wrote in comp.lang.c:
Laery wrote:

Hi,

I'm currently adding a new module to an old borland C3.1 application
(dos).
And I need to calculate a date by subtracting the number of days from
a given date.


Load the date into a struct tm, taking care to ensure that:

(a) all fields you don't set are cleared to 0, eg with:
struct tm date = (0); /* for now, just trust me on this */


ITYM struct tm date = { 0 };

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #6
In article <42************ ***@btinternet. com>,
in******@btinte rnet.com says...
Laery wrote:

Hi,

I'm currently adding a new module to an old borland C3.1 application
(dos).
And I need to calculate a date by subtracting the number of days from
a given date.


Load the date into a struct tm, taking care to ensure that:

(a) all fields you don't set are cleared to 0, eg with:
struct tm date = (0); /* for now, just trust me on this */


It would be more trustworthy with braces instead of parens. :-)

--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
Nov 14 '05 #7
Jack Klein wrote:

On Thu, 24 Feb 2005 11:04:15 +0000 (UTC), infobahn
<in******@btint ernet.com> wrote in comp.lang.c:
(a) all fields you don't set are cleared to 0, eg with:
struct tm date = (0); /* for now, just trust me on this */


ITYM struct tm date = { 0 };


I do indeed. I was clearly tempting fate a little too much with that
comment.
Nov 14 '05 #8
Randy Howard wrote:

In article <42************ ***@btinternet. com>,
in******@btinte rnet.com says...
Laery wrote:

Hi,

I'm currently adding a new module to an old borland C3.1 application
(dos).
And I need to calculate a date by subtracting the number of days from
a given date.


Load the date into a struct tm, taking care to ensure that:

(a) all fields you don't set are cleared to 0, eg with:
struct tm date = (0); /* for now, just trust me on this */


It would be more trustworthy with braces instead of parens. :-)


<sigh>
Some days, it just doesn't pay to fire up your newsreader. :-$
</sigh>
Nov 14 '05 #9
Hello Stan

If you could mail me a copy of the date library you are talking about,
that will be very kind of you. Just mail it to me at

ptiwaryATmahind rabtDOTcom

Thanks in advance.

Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4750
by: JP SIngh | last post by:
Hi All I need to calculate the number of working days between the two dates entered on an ASP page. I am not that great a coder in ASP and was wondering if someone can help. Basically the form has Two textboxes to enter dates From Date - Fdate To Date - TDate
28
742
by: Steve | last post by:
Hi all How would I find out the average date when given a bunch of dates? For example, I want to find the average length in time from the following dates: ---------------------------------------------------- Start Date End Date 01/01/2004 12:50pm 02/01/2004 18:40pm 02/01/2004 13:40pm 02/01/2004 13:57pm 02/01/2004 14:30pm 02/01/2004 19:50pm
26
4422
by: Frank | last post by:
For my website i would like to display the age of my son in years, months, days and hours. For now i manage to get a result for totals. Like the total number of days. This is the beginning: starttime = Date.parse("Aug 10,2003, 07:07") sdt = new Date(starttime)
8
25389
by: dlx_son | last post by:
Here is the code so far <form name="thisform"> <h3>Enter time to add to or subtract from:</h3> (If not entered, current time will be used)<br> Day: <input name="d1" alt="Day of month" size=3> Month: <input name="m1" alt="Month" size=3> Year: <input name="y1" alt="Year" size=5> (4 digits for year, e.g.
6
31824
by: charliewest | last post by:
Can someone pls point me to or recommend the easiest way to calculate someone´s age using the TimeSpan object, in .NET CF? Isn´t there a simple way to use the TimeSpan object to calculate the elapsed time and somehow convert the days to years w/out using the VB DLL? Thanks.
6
14454
by: rohayre | last post by:
Im a long time java developer and actually have never done anything with java scripting. I'd like to write a short simple script for calculating a date in the future based on today's date and a letter. Can I use javascripting to create a webpage to allow a user to enter a letter and then click a button to find a future calendar date? I'm just not sure how much user interaction scripting allows. Does java scripting allow buttons, textfields...
5
13675
by: Beemer Biker | last post by:
I cant seem to get that date into any DateTime to make my calculation directly by subtracting "01-01-0000" from "now". After reading this: http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=11469&objectType=File I kluged up this routine that works: // convert date time into that funny matlab serial date time that starts at jan 1, 0000 private string DT2Matlab(DateTime thisDT)
3
1304
by: shmoopie | last post by:
Hi, I have a php form that I want to use to pass a user specified "start date" and "end date" to a mysql database to retrieve reservations. I want the number of days up to and including the "end date" to be displayed for both of these scenarios: 1) The item is still on loan as of the "end date" 2) The item has already been returned as of the "end date" Right now I have it working by specifying a "start date", but the "end date" is...
5
24557
FishVal
by: FishVal | last post by:
IMHO, the following is not a how-to-do instruction to solve a particular problem but more a concept-proof stuff demonstrating possibilities of SQL. So, let us say the problem is to calculate business days count which is defined as count of days (optionally inclusive in the current implementation) excluding weekend days and holidays. Let us say periods to calculate are stored in table associated with contacts. keyPeriodID -...
0
9518
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10430
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10159
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9033
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2917
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.