View mode: basic / threaded / horizontal-split · Log in · Help
July 18, 2011
Re: std.datetime for month integer
Thank you, it works as planned, now as:
int mo = Now.month;  // --> 7

== Repost the article of Jonathan M Davis (
== Posted at 2011/07/18 12:14 to digitalmars.D.learn

On Monday 18 July 2011 16:01:06 dsmith wrote:
> Recall that used the following to retrieve a month in integer form
> (0 .. 11):
>   auto Now =;
>   writeln(;
> Using std.datetime, the following yields the abbreviated month name:
>   auto Now = Clock.currTime();
>   writefln("%s", Now.month);    // --> jul
> Now, how can std.datetime be used to print the month in integer form?

Cast it to an integer (or use will probably work - it _should_ at
least; if it doesn't, it needs to be fixed). std.datetime.Month is a named
enum. So, presumably that's why you're seeing it as a the enum's name. I think
that that's only happening because you're using it directly in writefln though.
If you assigned it to a variable first, I think that it would just be a ubyte,
since that's the type of the Month enum).

- Jonathan M Davis
Top | Discussion index | About this forum | D home