hello everybody,
I got a prob. I see a lot of date formats when I do a search in
Google. But can any one give me some pointers / an example to extract
today's date in C++ ? (formate of date: dd/mm/yyyy)
Thanks in advance 8 43784
"Abhijit" <ab*********@yahoo.com> wrote in message
news:45*************************@posting.google.co m... hello everybody,
I got a prob. I see a lot of date formats when I do a search in Google. But can any one give me some pointers / an example to extract today's date in C++ ? (formate of date: dd/mm/yyyy)
Thanks in advance
Untested code
#include <time.h>
#include <stdio.h>
time_t t = time(0);
tm* lt = localtime(t);
char date[11];
sprintf(date, "%02d/%02d/%04d", lt->tm_mday, lt->tm_mon + 1, lt->year +
1900);
john
"Abhijit" <ab*********@yahoo.com> wrote in message hello everybody,
I got a prob. I see a lot of date formats when I do a search in Google. But can any one give me some pointers / an example to extract today's date in C++ ? (formate of date: dd/mm/yyyy)
Take a look at functions in <ctime>. Also check Boost's Date-time library.
Sharad
> > I got a prob. I see a lot of date formats when I do a search in Google. But can any one give me some pointers / an example to extract today's date in C++ ? (formate of date: dd/mm/yyyy)
Thanks in advance
Untested code
#include <time.h> #include <stdio.h>
time_t t = time(0); tm* lt = localtime(t); char date[11]; sprintf(date, "%02d/%02d/%04d", lt->tm_mday, lt->tm_mon + 1, lt->year + 1900);
Or ...
#include <ctime>
#include <iostream>
const int MAXLEN = 80;
char s[MAXLEN];
time_t t = time(0);
cftime(s, "%D", &t);
std::cout << s << '\n';
David Fisher
Sydney, Australia
"David Fisher" <da***@hsa.com.au> wrote in message
news:dc****************@nasal.pacific.net.au... > I got a prob. I see a lot of date formats when I do a search in > Google. But can any one give me some pointers / an example to extract > today's date in C++ ? (formate of date: dd/mm/yyyy) > > Thanks in advance
Untested code
#include <time.h> #include <stdio.h>
time_t t = time(0); tm* lt = localtime(t); char date[11]; sprintf(date, "%02d/%02d/%04d", lt->tm_mday, lt->tm_mon + 1, lt->year + 1900);
Or ...
#include <ctime> #include <iostream>
const int MAXLEN = 80; char s[MAXLEN]; time_t t = time(0); cftime(s, "%D", &t); std::cout << s << '\n';
David Fisher Sydney, Australia
Never heard of cftime, did you mean strftime? If so then %D is part of the
C99 standard, though apparently widely supported.
john
John Harrison wrote: #include <ctime> #include <iostream>
const int MAXLEN = 80; char s[MAXLEN]; time_t t = time(0); cftime(s, "%D", &t); std::cout << s << '\n';
Never heard of cftime, did you mean strftime? If so then %D is part of the C99 standard, though apparently widely supported.
Hmm ... I'm not sure how standard cftime() is, actually - but it wasn't a
typo ...
Using strftime() it would be:
#include <ctime>
#include <iostream>
const int MAXLEN = 80;
char s[MAXLEN];
time_t t = time(0);
strftime(s, MAXLEN, "%m/%d/%Y", localtime(&t));
std::cout << s << '\n';
("%D" with strftime seems to only have 2 digits - ?)
David Fisher
Sydney, Australia
In article <2q*************@uni-berlin.de>,
John Harrison <jo*************@hotmail.com> wrote: "Abhijit" <ab*********@yahoo.com> wrote in message news:45*************************@posting.google.c om... [...] can any one give me some pointers / an example to extract today's date in C++ ? (formate of date: dd/mm/yyyy)
sprintf(date, "%02d/%02d/%04d", lt->tm_mday, lt->tm_mon + 1, lt->year +
I thought he was asking about how to *read* a date from an input stream.
--
Jon Bell <jt*******@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
"Jon Bell" <jt*******@presby.edu> wrote in message
news:ci**********@jtbell.presby.edu... In article <2q*************@uni-berlin.de>, John Harrison <jo*************@hotmail.com> wrote: "Abhijit" <ab*********@yahoo.com> wrote in message news:45*************************@posting.google.c om... [...] can any one give me some pointers / an example to extract today's date in C++ ? (formate of date: dd/mm/yyyy)
sprintf(date, "%02d/%02d/%04d", lt->tm_mday, lt->tm_mon + 1, lt->year +
I thought he was asking about how to *read* a date from an input stream.
You could well be right. Assuming said date is held in a C string, then
int day, month, year;
sscanf(date, "%d/%d/%d", &day, &month, &year);
does the trick, but with minimal error checking.
john ab*********@yahoo.com (Abhijit) wrote in message news:<45*************************@posting.google.c om>... I got a prob. I see a lot of date formats when I do a search in Google. But can any one give me some pointers / an example to extract today's date in C++ ? (formate of date: dd/mm/yyyy)
In Boost's ( www.boost.org) date time library you might use:
date from_uk_string(const std::string&)
Where the parameter is a delimited date string where with order
day-month-year eg: 25-1-2002.
Reference: http://www.boost.org/libs/date_time/doc/class_date.html
Hope this helps,
Matt Hurd www.hurd.com.au This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bob Sanderson |
last post by:
Does Access have a function to convert a date into a date code (i.e.
today's date would be displayed at 051805).
|
by: Jéjé |
last post by:
Hi,
how to setup a specific date/time format for my web site without having to
apply the format in each grid etc... ?
today the format include day, hour, minutes and seconds, I want only the...
|
by: TB |
last post by:
Hi All:
A kind soul provided by with the code for very nice calendar popup, which
all in all works fine execpt for one thing: If I pick the current date (i.e.
today's date) then the pop-up does...
|
by: TB |
last post by:
Hi All:
A kind soul provided by with the code for very nice calendar popup, which
all in all works fine execpt for one thing: If I pick the current date (i.e.
today's date) then the pop-up does...
|
by: joeyej |
last post by:
How do I compare today's date with this string (in my inc file) so that
I can set an alert if date choice i.e. May 15, 2006 not at least
greater than two days from current date?
<option...
| |
by: walterbyrd |
last post by:
My MySQL table has a field that is set as type "date." I need to get
today's date, and insert it into that field. The default for that MySQL
field is 2006-00-00.
I know about the date()...
|
by: M Skabialka |
last post by:
I am creating my first Visual Studio project, an inventory database. I have
created a form and used written directions to add data from a table to the
form using table adapters, data sets, etc.
...
|
by: Holmsey |
last post by:
Hi I have to convert am today's date and time (now) to a webservice.
The example the web service gives was "1163313527144#" which comes out
to 12/31/1969 06:00 PM. How do I convert a date to a 13...
|
by: Scott Kaempfe |
last post by:
I need to identify parts we buy at our plant. I want to give each a unique serial number that is based on the date. We may have multiple parts on a given date so I want to have the unique serial...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
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...
| |