|
Since you're using only date and no time, here is something you can do.
Create strings in the format yearmonthday. eg: 20101231.
Now you can do a direct comparison using the comparison operators.
|
|
|
|
|
Hello,
Thank you very much for the guidance of both of you.
I got it solved. Below is the code for the benefit of the readers :
<br />
<br />
#include <conio.h><br />
#include <time.h><br />
#include <atlstr.h><br />
#include <atltime.h><br />
<br />
<br />
void CompareDates();<br />
<br />
void main()<br />
{<br />
CompareDates();<br />
getch();<br />
}<br />
<br />
void CompareDates() <br />
{<br />
int nYear = 2010;<br />
int nMonth = 1;<br />
int nDay = 1;<br />
CString sYear;<br />
CString sMonth;<br />
CString sDay;<br />
long lDate1 = 0;<br />
long lDate2 = 0;<br />
CString sDate1;<br />
CString sDate2;<br />
<br />
sYear.Format("%d",nYear);<br />
<br />
if (nMonth < 10)<br />
sMonth.Format("0%d",nMonth);<br />
else<br />
sMonth.Format("%d",nMonth);<br />
<br />
if (nDay < 10)<br />
sDay.Format("0%d",nDay);<br />
else<br />
sDay.Format("%d",nDay);<br />
<br />
sDate1 = sYear + sMonth + sDay;<br />
<br />
CTime time = CTime::GetCurrentTime();<br />
sDate2.Format("%s%s%s",time.Format("%Y"),time.Format("%m"),time.Format("%d")); <br />
<br />
puts("sDate1 : " + sDate1);<br />
puts("sDate2 : " + sDate2);<br />
<br />
lDate1 = atol(sDate1);<br />
lDate2 = atol(sDate2);<br />
<br />
if(lDate1 >= lDate2) <br />
{<br />
puts("more");<br />
}<br />
else <br />
{<br />
puts("less");<br />
}<br />
}<br />
<br />
with warmest regards,
Goutam
modified on Wednesday, October 6, 2010 4:11 AM
|
|
|
|
|
Or...
void CompareDates( void )
{
int nYear = 2010;
int nMonth = 1;
int nDay = 1;
CString sDate1;
CString sDate2;
sDate1.Format("%d%02d%02d", nYear, nMonth, nDay);
CTime time = CTime::GetCurrentTime();
sDate2.Format("%s%s%s",time.Format("%Y"),time.Format("%m"),time.Format("%d"));
puts("sDate1 : " + sDate1);
puts("sDate2 : " + sDate2);
if (sDate1 >= sDate2)
puts("more");
else
puts("less");
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
|
Hi Guys, I am using CDateTimeCtrl in my project.I dont know how to get Date, Month and Year Separatly.
If you Know explain me with simple code
Thanks in Advance
|
|
|
|
|
How about reading the documentation in MSDN and letting us know what you did not understand after seeing the member functions of this class to get the date, month and year separately?
Read GetTime function and refer the SYSTEMTIME structure.
I am a HUMAN. I have that keyword (??? too much) in my name........
_AnsHUMAN_b>
|
|
|
|
|
|
Use the method "GetTime" and then Format the CTime-object.
Example to get the month:
CTime timeTime;
theDateTimeCtrl.GetTime(timeTime);
CString strMonth(timeTime.Format(_T("%m"));
Now the Month is in the string.
Look in the documentation of strftime to get the formatting codes.
|
|
|
|
|
hi,i'm currently doing a project using a software,Waspmote. I have some problems with my codings,it gave me 2 errors when i tried correcting it,
In function 'void loop()':
error: expected initializer before 'uint8_t'
In function 'void loop()':
error: a function-definition is not allowed here before '{' token
could anyone kindly help me take a look at the codings and suggest ways for me to improve on it.The code is as shown below:
int n=0;
void setup(){
// setup for Serial port over USB
USB.begin();
USB.println("USB port started...");
USB.close();
// Powering BT
BT.ON();
// Init
if(!BT.init()) USB.println("Init OK");
}
void loop()
{
// Searching for devices
if(!BT.scanNetwork()) USB.println("Scan OK");
else USB.println("Scan failed");
// Printing the devices that have been found
for(int l=0;l<BT.devices_found;l++)
{
n=0;
USB.print("---- DEVICE ");
USB.print(l,DEC);
USB.print(" ---- ");
USB.print("MAC: ");
for(int m=0;m<12;m++)
{
USB.print(BT.discovered_devices[l].mac_address[m],BYTE);
}
USB.print(" -- NAME: ");
while(BT.discovered_devices[l].name[n]!='\0')
{
USB.print(BT.discovered_devices[l].name[n],BYTE);
n++;
}
n=0;
USB.print(" -- CoD: ");
while(BT.discovered_devices[l].CoD[n]!='\0')
{
USB.print(BT.discovered_devices[l].CoD[n],BYTE);
n++;
}
USB.println("");
delay(2000);
}
// Creating a connection to a device
if(!BT.createConnection("0017E5F1CF74","02"))
{
USB.println("");
USB.print("--- CONNECTION -- MTU: ");
USB.print(BT.connection_mtu[0],BYTE);
USB.print(BT.connection_mtu[1],BYTE);
USB.println(BT.connection_mtu[2],BYTE);
}
else USB.println("Connection failed");
delay(1000);
void printData(char* data )
{
uint8_t uart=0;
printString(data,uart);
printByte('\r',uart);
printByte('\n',uart);
}
delay(2000);
return ;
}
|
|
|
|
|
Check where you put your braces { }. It looks to me like your "printData()" function is INSIDE "loop()". Indenting your code neatly NEVER hurts and often (in cases like this) helps you see what you've written.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
thanks for the reply.I tried removing the brackets but it still doesn't work,if possible may i just trouble you to help me correct the codings because i'm rather new in programming.
|
|
|
|
|
I didn't say remove the braces. You need to get them matching correctly, like this:
func1() {
...
...
}
func2() {
...
...
}
What you had is more like
func1() {
...
...
func2() {
...
...
}
}
See how the indentation makes it easy to spot the problem?
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
After looking through the codes and compiling, I still get an error:
In function 'void loop()':
error: a function-definition is not allowed here before '{' token
int n=0;
void setup()
{
USB.begin();
USB.println("USB port started...");
USB.close();
BT.ON();
if(!BT.init()) USB.println("Init OK");
}
void loop()
{
if(!BT.scanNetwork()) USB.println("Scan OK");
else USB.println("Scan failed");
for(int l=0;l<BT.devices_found;l++)
{
n=0;
USB.print("---- DEVICE ");
USB.print(l,DEC);
USB.print(" ---- ");
USB.print("MAC: ");
for(int m=0;m<12;m++)
{
USB.print(BT.discovered_devices[l].mac_address[m],BYTE);
}
USB.print(" -- NAME: ");
while(BT.discovered_devices[l].name[n]!='\0')
{
USB.print(BT.discovered_devices[l].name[n],BYTE);
n++;
}
n=0;
USB.print(" -- CoD: ");
while(BT.discovered_devices[l].CoD[n]!='\0')
{
USB.print(BT.discovered_devices[l].CoD[n],BYTE);
n++;
}
USB.println("");
delay(2000);
}
if(!BT.createConnection("0017E5F1CF74","02"))
{
USB.println("");
USB.print("--- CONNECTION -- MTU: ");
USB.print(BT.connection_mtu[0],BYTE);
USB.print(BT.connection_mtu[1],BYTE);
USB.println(BT.connection_mtu[2],BYTE);
}
else USB.println("Connection failed");
delay(1000);
void printData(char* data )
{
uint8_t uart=0;
printString(data,uart);
printByte('\r',uart);
printByte('\n',uart);
}
delay(2000);
return ;
}
|
|
|
|
|
I just pasted that code into my syntax-highlighting editor, and it tells me that the very last close brace matches the one immediately after void loop() . So void printData() is still "inside" void loop() . Again, the indenting should give you a clue - void printData() isn't in column 1 like the other functions are.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
I taken
void printData out from the
loop .There are no more errors,but when i upload the codings to the waspmote IDE, it doesn't send out the text to external devices through the bluetooth device.Do you have any recommendations for me to modify my existing source code?
|
|
|
|
|
dusk85 wrote: Do you have any recommendations for me to modify my existing source code?
Quote Selected Text
The short answer is no. I am happy to help with getting your code to compile, but I'm not going into your bluetooth issues. I suggest you try a forum for bluetooth or waspmote (whatever that is).
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
You really should never present unformatted code. Using PRE tags would preserve indentation and make things readable, and maybe the mistake obvious.
|
|
|
|
|
Does anyone know if I can make the SDK 7.1 directories the default instead of using the SDK 7.0!
I know that you can configure them on each solution, but it is very boring to set them on each solution.
Or should I copy and replace files of 7.0A with 7.1.
(Might even free up some disk space in the process)
|
|
|
|
|
Does anyone know if the new mysql libraries can be called from the old old vc6 (on windows xp)?
thanks!
|
|
|
|
|
Yes, they perfectly work togheter ... swend me an email, and I'll send to you a test application ...
|
|
|
|
|
If I assign a string to a variable.
char* t = "Hello World!";
Doesn't this string get a fixed array with a null terminator at the end?
|
|
|
|
|
Yes. Take a look at it in the debugger if you are not sure.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
wcscat_s keeps throwing an error that the string isn't null terminated! :S
|
|
|
|
|
Are you sure it doesn't throw an exception, because the memory provided in strDestination argument is read-only?
|
|
|
|
|
Fareed Rizkalla wrote: wcscat_s keeps throwing an error that the string isn't null terminated!
Yes, I'm not surprised since you are sending it a char* (i.e. ASCII string) but wcscat_s() expects Unicode.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|