Formatting dates

Hi all,

I have a column vector with dates formatted yyyymm. Originally, this vector printed as yyyymm.00, but I changed the format using the format command and now it prints as yyyymm. I've been trying to set this as a date variable, but the dttostr command returns a vector in which each entry reads "0000-00", dttodtv returns an eight-column matrix whose first row is "-1 11 30 20 6 7 3 333" (the first entry in the column vector of dates is "200607"), and dtvtodt returns an error G0036: matrices are not conformable. How are my date values formatted, and how can I change them to a format I can work with?

5 Answers



0



Try this code snippet here:

//July of 2006 through January of 2007
d = { 200607,
      200608,
      200609,
      200610,
      200611,
      200612,
      200701 };

date_str = dttostr(d, "YYYY-MO");
print date_str;

In GAUSS 15 I get this output, which I think is what you want:

2006-07 
2006-08 
2006-09 
2006-10 
2006-11 
2006-12 
2007-01

aptech

1,773


0



Thanks! That output is what I want, but when I try the code you gave me it returns a column vector with each entry equal to 0000-00. Thoughts?

dcm

0


0



Hmmm...what version of GAUSS are you running and what operating system?

aptech

1,773


0



I believe it's V10, and I'm in Windows.

dcm

0


0



OK, I think in version 12 or 13 is when GAUSS first allowed these scalar numeric dates (DT Scalar Format) to have as fewer than 14 digits before the decimal place. The full DT Scalar is: year, month, day, hour, minute, second, like this:

YYYYMODDHHMISS
YYYY -> Year
MO   -> Month
DD   -> Day
HH   -> Hour
MI   -> Minute
SS   -> Second

For a specific example: October, 24th 2015 at 8:45 am would be:

20151024084500

GAUSS 10 requires you to include all 14 digits. Current versions of GAUSS only require you to specify the first 4 digits for the year and anything after that is optional. So for GAUSS 10, you need to change the original example to this:

//July of 2006 through January of 2007
d = { 200607,
      200608,
      200609,
      200610,
      200611,
      200612,
      200701 };

//Adjustment to 'full dtscalar format' for GAUSS 10
d = d * 1e8;

date_str = dttostr(d, "YYYY-MO");
print date_str;

aptech

1,773

Your Answer

5 Answers

0

Try this code snippet here:

//July of 2006 through January of 2007
d = { 200607,
      200608,
      200609,
      200610,
      200611,
      200612,
      200701 };

date_str = dttostr(d, "YYYY-MO");
print date_str;

In GAUSS 15 I get this output, which I think is what you want:

2006-07 
2006-08 
2006-09 
2006-10 
2006-11 
2006-12 
2007-01
0

Thanks! That output is what I want, but when I try the code you gave me it returns a column vector with each entry equal to 0000-00. Thoughts?

0

Hmmm...what version of GAUSS are you running and what operating system?

0

I believe it's V10, and I'm in Windows.

0

OK, I think in version 12 or 13 is when GAUSS first allowed these scalar numeric dates (DT Scalar Format) to have as fewer than 14 digits before the decimal place. The full DT Scalar is: year, month, day, hour, minute, second, like this:

YYYYMODDHHMISS
YYYY -> Year
MO   -> Month
DD   -> Day
HH   -> Hour
MI   -> Minute
SS   -> Second

For a specific example: October, 24th 2015 at 8:45 am would be:

20151024084500

GAUSS 10 requires you to include all 14 digits. Current versions of GAUSS only require you to specify the first 4 digits for the year and anything after that is optional. So for GAUSS 10, you need to change the original example to this:

//July of 2006 through January of 2007
d = { 200607,
      200608,
      200609,
      200610,
      200611,
      200612,
      200701 };

//Adjustment to 'full dtscalar format' for GAUSS 10
d = d * 1e8;

date_str = dttostr(d, "YYYY-MO");
print date_str;

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.