473,321 Members | 1,778 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,321 software developers and data experts.

Question about SYSTEMTIME

Hi,
I want to get the (SYSTEMTIME -15) minuts in windows in C. How can I do
it?
I start like that:

SYSTEMTIME time_old, time_now;

GetLocalTime(&time_old);
GetLocalTime(&time_now);

And now I must have in time_old the SYSTEMTIME - 15 minutes, is there
any implemented function in C to do in (it must work in windows not in
unix).

I'll be very gratefull for any sugestions.

Thank you very much for help

Ralph

Sep 11 '06 #1
5 7299
"ralph" <rk******@o2.plwrites:
I want to get the (SYSTEMTIME -15) minuts in windows in C. How can I do
it?
I start like that:

SYSTEMTIME time_old, time_now;

GetLocalTime(&time_old);
GetLocalTime(&time_now);

And now I must have in time_old the SYSTEMTIME - 15 minutes, is there
any implemented function in C to do in (it must work in windows not in
unix).
There is no SYSTEMTIME type or GetLocalTime() function in standard C.
Since you say the problem is Windows-specific, you need to ask in a
Windows-specific newsgroup.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 11 '06 #2
MQ

ralph wrote:
Hi,
I want to get the (SYSTEMTIME -15) minuts in windows in C. How can I do
it?
I start like that:

SYSTEMTIME time_old, time_now;

GetLocalTime(&time_old);
GetLocalTime(&time_now);
Did you look at the format of the SYSTEMTIME structure? It has fields
like wHour, wMinute, wSecond, etc. I imagine the code would be
something like

if(time_old.wMinute < 15)
{
time_old.wHour--;
time_old.wMinute = 45 + time_old.wMinute;
/* not complete, more must be added */
}
else
{
time_old.wMinute -= 15;
}

I'll leave it as an exercise for you to add the rest of the code for
handling day, week, month, year, etc boundaries, which is actually not
that trivial... Consult MSDN for the details of the SYSTEMTIME
structure. And before you get bombarded by cranky clc regulars about
the inappropriateness of the post in this purely C newsgroup, I would
suggest posting platform-specific (eg Windows) questions on an MS
forum. I don't have a problem with it, but you will find some do... :)

cheers
MQ

Sep 11 '06 #3
MQ wrote:
ralph wrote:
>Hi,
I want to get the (SYSTEMTIME -15) minuts in windows in C. How can I do
it?
I start like that:

SYSTEMTIME time_old, time_now;

GetLocalTime(&time_old);
GetLocalTime(&time_now);

Did you look at the format of the SYSTEMTIME structure? It has fields
like wHour, wMinute, wSecond, etc. I imagine the code would be
something like

if(time_old.wMinute < 15)
{
time_old.wHour--;
time_old.wMinute = 45 + time_old.wMinute;
/* not complete, more must be added */
}
else
{
time_old.wMinute -= 15;
}

I'll leave it as an exercise for you to add the rest of the code for
handling day, week, month, year, etc boundaries, which is actually not
that trivial... Consult MSDN for the details of the SYSTEMTIME
structure. And before you get bombarded by cranky clc regulars about
the inappropriateness of the post in this purely C newsgroup, I would
suggest posting platform-specific (eg Windows) questions on an MS
forum. I don't have a problem with it, but you will find some do... :)
As an alternative either:
1. Use whatever routine this platform has for converting SYSTEMTIME
to a single number (in seconds, milliseconds or whatever) and
subtract the right amount, then convert back.
2. Use the C function time to get the time in seconds, subtract
15*60, use localtime to convert the result to struct_tm.

--
imalone
Sep 11 '06 #4
MQ

Ian Malone wrote:
As an alternative either:
1. Use whatever routine this platform has for converting SYSTEMTIME
to a single number (in seconds, milliseconds or whatever) and
subtract the right amount, then convert back.
2. Use the C function time to get the time in seconds, subtract
15*60, use localtime to convert the result to struct_tm.
Yes, this is probably easier. Let the OS/libraries do the work

MQ

Sep 11 '06 #5
Ian Malone <ib***@cam.ac.ukwrites:
[snip]
As an alternative either:
1. Use whatever routine this platform has for converting SYSTEMTIME
to a single number (in seconds, milliseconds or whatever) and
subtract the right amount, then convert back.
2. Use the C function time to get the time in seconds, subtract
15*60, use localtime to convert the result to struct_tm.
The latter assumes that time_t represents the time in seconds. It
commonly does, but there is no such guarantee (or implication) in the
C standard.

If you need portability, you can convert a time_t value to a struct tm
using localtime(), manipulate the members of the struct tm, then
convert it back using mktime().

If you don't care about absolute portability (e.g., if your platform
happens to make guarantees about the representation of time_t, and
your code is already platform-specific anyway), you can probably get
away with performing arithmetic directly on a time_t. Or you can
consult your system's documentation for solutions.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 11 '06 #6

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

Similar topics

3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
7
by: LT | last post by:
Hello, I have the following problem. I'm using the CMonthCalCtrl calendar control. I need to emphasize some of days, so I'm handling the MCN_GETDAYSTATE event. The problem is when my handler...
2
by: banski | last post by:
Hi, Im trying to find out how to convert a SYSTEMTIME to BSTR. Cant find out how to do that. Hopefully some of you could help me out. Best regards Thomas
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
7
by: Kevin | last post by:
Hi al I have an interesting question.... I am working witha Win API this is the Function Public Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" (ByVal hPrinter As Long, ByVal...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
1
by: mappla | last post by:
Hi , How to prevent any one can freeze or suspended or stop the system Time . what are the possibilites to prevent or protect the to freeze the SystemTime. regards ranjith
4
by: Benny Van | last post by:
Hi all! I have a question regarding a windows operating system function: I was asked to write a small program for a homework to display the user name and computer name and the system time out to a...
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...
1
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.