converting QuantLib date back to mm/dd/yyyy

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

converting QuantLib date back to mm/dd/yyyy

Pavan Shah-2
hello,
I am trying to output dates into a csv file in one cell .  However, right now they are being output as  June 22nd       2012   in two different cells.

I just used the ofstream object to ouput (nothing fancy).

How can I convert a QuantLib date into mm/dd/yyyy and ensure that it is output in one cell?

thanks
Pavan

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: converting QuantLib date back to mm/dd/yyyy

Pavan Shah-2
does anyone have a suggestion?
thanks
Pavan


On Tue, Jan 29, 2013 at 8:08 AM, Pavan Shah <[hidden email]> wrote:
hello,
I am trying to output dates into a csv file in one cell .  However, right now they are being output as  June 22nd       2012   in two different cells.

I just used the ofstream object to ouput (nothing fancy).

How can I convert a QuantLib date into mm/dd/yyyy and ensure that it is output in one cell?

thanks
Pavan


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: converting QuantLib date back to mm/dd/yyyy

Piter Dias-4

You may try io::short_date(date) at date.hpp.

 

On 2013-01-29 21:53, Pavan Shah wrote:

does anyone have a suggestion?
thanks
Pavan


On Tue, Jan 29, 2013 at 8:08 AM, Pavan Shah <[hidden email]> wrote:
hello,
I am trying to output dates into a csv file in one cell .  However, right now they are being output as  June 22nd       2012   in two different cells.
 
I just used the ofstream object to ouput (nothing fancy).
 
How can I convert a QuantLib date into mm/dd/yyyy and ensure that it is output in one cell?
 
thanks
Pavan

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan

_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

 

-- 
________________________ Piter Dias [hidden email] www.piterdias.com

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: converting QuantLib date back to mm/dd/yyyy

Oleg Goldshmidt
In reply to this post by Pavan Shah-2
On Tue, Jan 29, 2013 at 6:08 PM, Pavan Shah <[hidden email]> wrote:

> How can I convert a QuantLib date into mm/dd/yyyy and ensure that it is
> output in one cell?

If you have Date d you can do

        char s[11] = {0};
        snprintf(s,11,"%02d/%02d/%04d",d.month(),d.dayOfMonth(),d.year());

- then output s. It's not a QuantLib-specific question - it looks like
basic C/C++ ?

--
Oleg Goldshmidt | [hidden email]

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

R: converting QuantLib date back to mm/dd/yyyy

Ballabio Gerardo-4
Da: Oleg Goldshmidt [mailto:[hidden email]]
> It's not a QuantLib-specific question - it looks like basic C/C++ ?

Since when is Date part of standard C/C++?

Also, snprintf is the C way to print things. Sure you can use it in C++, too, but if you'd like to do things "in the C++ style", you should use streams:

  std::ofstream outfile("...");
  outfile << d.month() << "/" << d.dayOfMonth() << "/" << d.year();

This won't give you trailing zeros, i.e., 1 January 2013 will show up as 1/1/2013 rather than 01/01/2013. If you need the zeros, you can use manipulators. Something like this:

  #include <iomanip>
  outfile << std::setwidth(2) << std::setfill('0') << d.month() << "/" << std::setwidth(2) << std::setfill('0') << d.dayOfMonth() << "/" << d.year();

but check the syntax because I don't use these very often and I'm not sure this is correct. I'm not sure either that the second setfill is required (I am quite sure the setwidth is).

Gerardo


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<div style="font-family:Calibri;font-size:10px">
Banca Profilo S.p.A.
Corso Italia, 49 - 20122 Milano - Tel. 02 58408.1, Fax 02 5831 6057
Capitale Sociale Euro 136.794.106,00 i.v.
Iscrizione al Registro Imprese di Milano, C.F. e P.IVA 09108700155 - [hidden email]
Iscritta all’Albo delle Banche e dei Gruppi bancari
Aderente al Fondo Interbancario di Tutela dei depositi
Aderente al Conciliatore Bancario Finanziario e all’Arbitro Bancario Finanziario
Appartenente al Gruppo bancario Banca Profilo e soggetta all’attività di direzione e coordinamento di Arepo BP S.p.A.


DISCLAIMER:
The information transmitted may contain confidential and/or privileged material.
Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon,
this information by persons or entities other than the intended recipient is prohibited.
If you received this in error, please contact the sender and delete the material from any computer.
</div>
</body>
</html>


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: R: converting QuantLib date back to mm/dd/yyyy

Luigi Ballabio
or

outfile << io::short_date(d);

as Piter suggested earlier. Internally, it uses manipulators like you
did (and restores their status after it's done).

Luigi


On Wed, Jan 30, 2013 at 2:54 PM, Ballabio Gerardo
<[hidden email]> wrote:

> Da: Oleg Goldshmidt [mailto:[hidden email]]
>> It's not a QuantLib-specific question - it looks like basic C/C++ ?
>
> Since when is Date part of standard C/C++?
>
> Also, snprintf is the C way to print things. Sure you can use it in C++, too, but if you'd like to do things "in the C++ style", you should use streams:
>
>   std::ofstream outfile("...");
>   outfile << d.month() << "/" << d.dayOfMonth() << "/" << d.year();
>
> This won't give you trailing zeros, i.e., 1 January 2013 will show up as 1/1/2013 rather than 01/01/2013. If you need the zeros, you can use manipulators. Something like this:
>
>   #include <iomanip>
>   outfile << std::setwidth(2) << std::setfill('0') << d.month() << "/" << std::setwidth(2) << std::setfill('0') << d.dayOfMonth() << "/" << d.year();
>
> but check the syntax because I don't use these very often and I'm not sure this is correct. I'm not sure either that the second setfill is required (I am quite sure the setwidth is).
>
> Gerardo
>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head></head>
> <body>
> <div style="font-family:Calibri;font-size:10px">
> Banca Profilo S.p.A.
> Corso Italia, 49 - 20122 Milano - Tel. 02 58408.1, Fax 02 5831 6057
> Capitale Sociale Euro 136.794.106,00 i.v.
> Iscrizione al Registro Imprese di Milano, C.F. e P.IVA 09108700155 - [hidden email]
> Iscritta all’Albo delle Banche e dei Gruppi bancari
> Aderente al Fondo Interbancario di Tutela dei depositi
> Aderente al Conciliatore Bancario Finanziario e all’Arbitro Bancario Finanziario
> Appartenente al Gruppo bancario Banca Profilo e soggetta all’attività di direzione e coordinamento di Arepo BP S.p.A.
>
>
> DISCLAIMER:
> The information transmitted may contain confidential and/or privileged material.
> Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon,
> this information by persons or entities other than the intended recipient is prohibited.
> If you received this in error, please contact the sender and delete the material from any computer.
> </div>
> </body>
> </html>
>
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_jan
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: R: converting QuantLib date back to mm/dd/yyyy

Pavan Shah-2
sorry Luigi, peter
but which header file do I need to have as my include directive?

thanks
pavan


On Wed, Jan 30, 2013 at 6:06 AM, Luigi Ballabio <[hidden email]> wrote:
or

outfile << io::short_date(d);

as Piter suggested earlier. Internally, it uses manipulators like you
did (and restores their status after it's done).

Luigi


On Wed, Jan 30, 2013 at 2:54 PM, Ballabio Gerardo
<[hidden email]> wrote:
> Da: Oleg Goldshmidt [mailto:[hidden email]]
>> It's not a QuantLib-specific question - it looks like basic C/C++ ?
>
> Since when is Date part of standard C/C++?
>
> Also, snprintf is the C way to print things. Sure you can use it in C++, too, but if you'd like to do things "in the C++ style", you should use streams:
>
>   std::ofstream outfile("...");
>   outfile << d.month() << "/" << d.dayOfMonth() << "/" << d.year();
>
> This won't give you trailing zeros, i.e., 1 January 2013 will show up as 1/1/2013 rather than 01/01/2013. If you need the zeros, you can use manipulators. Something like this:
>
>   #include <iomanip>
>   outfile << std::setwidth(2) << std::setfill('0') << d.month() << "/" << std::setwidth(2) << std::setfill('0') << d.dayOfMonth() << "/" << d.year();
>
> but check the syntax because I don't use these very often and I'm not sure this is correct. I'm not sure either that the second setfill is required (I am quite sure the setwidth is).
>
> Gerardo
>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head></head>
> <body>
> <div style="font-family:Calibri;font-size:10px">
> Banca Profilo S.p.A.
> Corso Italia, 49 - 20122 Milano - Tel. 02 58408.1, Fax 02 5831 6057
> Capitale Sociale Euro 136.794.106,00 i.v.
> Iscrizione al Registro Imprese di Milano, C.F. e P.IVA 09108700155 - [hidden email]
> Iscritta all’Albo delle Banche e dei Gruppi bancari
> Aderente al Fondo Interbancario di Tutela dei depositi
> Aderente al Conciliatore Bancario Finanziario e all’Arbitro Bancario Finanziario
> Appartenente al Gruppo bancario Banca Profilo e soggetta all’attività di direzione e coordinamento di Arepo BP S.p.A.
>
>
> DISCLAIMER:
> The information transmitted may contain confidential and/or privileged material.
> Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon,
> this information by persons or entities other than the intended recipient is prohibited.
> If you received this in error, please contact the sender and delete the material from any computer.
> </div>
> </body>
> </html>
>
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_jan
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: R: converting QuantLib date back to mm/dd/yyyy

Luigi Ballabio
short_date is in <ql/time/date.hpp>, which you're already including if
you're using the Date class.  What is the error?

On Thu, Jan 31, 2013 at 5:32 PM, Pavan Shah <[hidden email]> wrote:

> sorry Luigi, peter
> but which header file do I need to have as my include directive?
>
> thanks
> pavan
>
>
> On Wed, Jan 30, 2013 at 6:06 AM, Luigi Ballabio <[hidden email]>
> wrote:
>>
>> or
>>
>> outfile << io::short_date(d);
>>
>> as Piter suggested earlier. Internally, it uses manipulators like you
>> did (and restores their status after it's done).
>>
>> Luigi
>>
>>
>> On Wed, Jan 30, 2013 at 2:54 PM, Ballabio Gerardo
>> <[hidden email]> wrote:
>> > Da: Oleg Goldshmidt [mailto:[hidden email]]
>> >> It's not a QuantLib-specific question - it looks like basic C/C++ ?
>> >
>> > Since when is Date part of standard C/C++?
>> >
>> > Also, snprintf is the C way to print things. Sure you can use it in C++,
>> > too, but if you'd like to do things "in the C++ style", you should use
>> > streams:
>> >
>> >   std::ofstream outfile("...");
>> >   outfile << d.month() << "/" << d.dayOfMonth() << "/" << d.year();
>> >
>> > This won't give you trailing zeros, i.e., 1 January 2013 will show up as
>> > 1/1/2013 rather than 01/01/2013. If you need the zeros, you can use
>> > manipulators. Something like this:
>> >
>> >   #include <iomanip>
>> >   outfile << std::setwidth(2) << std::setfill('0') << d.month() << "/"
>> > << std::setwidth(2) << std::setfill('0') << d.dayOfMonth() << "/" <<
>> > d.year();
>> >
>> > but check the syntax because I don't use these very often and I'm not
>> > sure this is correct. I'm not sure either that the second setfill is
>> > required (I am quite sure the setwidth is).
>> >
>> > Gerardo
>> >
>> >
>> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
>> > <html xmlns="http://www.w3.org/1999/xhtml">
>> > <head></head>
>> > <body>
>> > <div style="font-family:Calibri;font-size:10px">
>> > Banca Profilo S.p.A.
>> > Corso Italia, 49 - 20122 Milano - Tel. 02 58408.1, Fax 02 5831 6057
>> > Capitale Sociale Euro 136.794.106,00 i.v.
>> > Iscrizione al Registro Imprese di Milano, C.F. e P.IVA 09108700155 -
>> > [hidden email]
>> > Iscritta all’Albo delle Banche e dei Gruppi bancari
>> > Aderente al Fondo Interbancario di Tutela dei depositi
>> > Aderente al Conciliatore Bancario Finanziario e all’Arbitro Bancario
>> > Finanziario
>> > Appartenente al Gruppo bancario Banca Profilo e soggetta all’attività di
>> > direzione e coordinamento di Arepo BP S.p.A.
>> >
>> >
>> > DISCLAIMER:
>> > The information transmitted may contain confidential and/or privileged
>> > material.
>> > Any review, retransmission, dissemination or other use of, or taking of
>> > any action in reliance upon,
>> > this information by persons or entities other than the intended
>> > recipient is prohibited.
>> > If you received this in error, please contact the sender and delete the
>> > material from any computer.
>> > </div>
>> > </body>
>> > </html>
>> >
>> >
>> >
>> > ------------------------------------------------------------------------------
>> > Everyone hates slow websites. So do we.
>> > Make your web apps faster with AppDynamics
>> > Download AppDynamics Lite for free today:
>> > http://p.sf.net/sfu/appdyn_d2d_jan
>> > _______________________________________________
>> > QuantLib-users mailing list
>> > [hidden email]
>> > https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
>

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: R: converting QuantLib date back to mm/dd/yyyy

Pavan Shah-2
no error
I haven't tried it yet because I didn't have this as my include directive.

No, I have been using <ql/quantlib.hpp>  and  <ql/utilities/dataparsers.hpp> .

I have been using Date class with these two directives.

I will give it a try with <ql/time/date.hpp>

thanks
Pavan


On Thu, Jan 31, 2013 at 9:04 AM, Luigi Ballabio <[hidden email]> wrote:
short_date is in <ql/time/date.hpp>, which you're already including if
you're using the Date class.  What is the error?

On Thu, Jan 31, 2013 at 5:32 PM, Pavan Shah <[hidden email]> wrote:
> sorry Luigi, peter
> but which header file do I need to have as my include directive?
>
> thanks
> pavan
>
>
> On Wed, Jan 30, 2013 at 6:06 AM, Luigi Ballabio <[hidden email]>
> wrote:
>>
>> or
>>
>> outfile << io::short_date(d);
>>
>> as Piter suggested earlier. Internally, it uses manipulators like you
>> did (and restores their status after it's done).
>>
>> Luigi
>>
>>
>> On Wed, Jan 30, 2013 at 2:54 PM, Ballabio Gerardo
>> <[hidden email]> wrote:
>> > Da: Oleg Goldshmidt [mailto:[hidden email]]
>> >> It's not a QuantLib-specific question - it looks like basic C/C++ ?
>> >
>> > Since when is Date part of standard C/C++?
>> >
>> > Also, snprintf is the C way to print things. Sure you can use it in C++,
>> > too, but if you'd like to do things "in the C++ style", you should use
>> > streams:
>> >
>> >   std::ofstream outfile("...");
>> >   outfile << d.month() << "/" << d.dayOfMonth() << "/" << d.year();
>> >
>> > This won't give you trailing zeros, i.e., 1 January 2013 will show up as
>> > 1/1/2013 rather than 01/01/2013. If you need the zeros, you can use
>> > manipulators. Something like this:
>> >
>> >   #include <iomanip>
>> >   outfile << std::setwidth(2) << std::setfill('0') << d.month() << "/"
>> > << std::setwidth(2) << std::setfill('0') << d.dayOfMonth() << "/" <<
>> > d.year();
>> >
>> > but check the syntax because I don't use these very often and I'm not
>> > sure this is correct. I'm not sure either that the second setfill is
>> > required (I am quite sure the setwidth is).
>> >
>> > Gerardo
>> >
>> >
>> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
>> > <html xmlns="http://www.w3.org/1999/xhtml">
>> > <head></head>
>> > <body>
>> > <div style="font-family:Calibri;font-size:10px">
>> > Banca Profilo S.p.A.
>> > Corso Italia, 49 - 20122 Milano - Tel. 02 58408.1, Fax 02 5831 6057
>> > Capitale Sociale Euro 136.794.106,00 i.v.
>> > Iscrizione al Registro Imprese di Milano, C.F. e P.IVA 09108700155 -
>> > [hidden email]
>> > Iscritta all’Albo delle Banche e dei Gruppi bancari
>> > Aderente al Fondo Interbancario di Tutela dei depositi
>> > Aderente al Conciliatore Bancario Finanziario e all’Arbitro Bancario
>> > Finanziario
>> > Appartenente al Gruppo bancario Banca Profilo e soggetta all’attività di
>> > direzione e coordinamento di Arepo BP S.p.A.
>> >
>> >
>> > DISCLAIMER:
>> > The information transmitted may contain confidential and/or privileged
>> > material.
>> > Any review, retransmission, dissemination or other use of, or taking of
>> > any action in reliance upon,
>> > this information by persons or entities other than the intended
>> > recipient is prohibited.
>> > If you received this in error, please contact the sender and delete the
>> > material from any computer.
>> > </div>
>> > </body>
>> > </html>
>> >
>> >
>> >
>> > ------------------------------------------------------------------------------
>> > Everyone hates slow websites. So do we.
>> > Make your web apps faster with AppDynamics
>> > Download AppDynamics Lite for free today:
>> > http://p.sf.net/sfu/appdyn_d2d_jan
>> > _______________________________________________
>> > QuantLib-users mailing list
>> > [hidden email]
>> > https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
>


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users