datetime.format for quarter

  • Thread starter Thread starter Dominique Vandensteen
  • Start date Start date
D

Dominique Vandensteen

I have a datetime and want to format it to "quarter year"
so 20 december 2003 should give: "4-2003"

is this possible?
I don't find a format character for quarter :-(


Dominique
 
Hi Dominique,

I thought that if there was one who knows a lot of dates it was you.
\\\
CInt((Now.Month + 2) / 3).ToString & "-" & Now.Year
////

Would give your result I thought.

Cor
 
yes but no :-)

I need something like:
dim x as DateTime = Now()
dim s as String = x.ToString("quarter-yyyy")

I know how to do it "manualy" but I get the formatstring out of a database
so your "manual" solution is not a solution in this case...
 
Hi Dominique,

I do not see the problem

Dim datum As Date
datum = DirectCast(dr("mydate"), Date)
dim s as String = CInt((Datum.Month + 2) / 3).ToString & "-" & Datum.Year

What do I see wrong?

If it is with databinding I can it also, but I cannot bring a quarter back
to a date in February.

Cor
 
well the problem is this

dim theStringOutOfMyDataBase as String

.... get string out of database...

dim datum as DateTime = Now()
dim showThisOnScreen as String = datum.ToString(theStringOutOfMyDataBase)



theStringOutOfMyDataBase can be for example "dd-MM-yyyy", "MM-yyyy",...
but it should also be able to show the quarter...

so the database contains only a format ("dd-MM-yyyy", "MM-yyyy",...)


the only thing I see if quarter doesn't have a format character is to
introduce one and "pre-format" the formatstring :-)
but this is a unkewl solution...
 
Hi Dominique,

If the MM is always written in the string as 01, 02, 03, etc you can because
it is a string make your own function, Q-yyyy and that is than all
equivalents of 1-yyyy etc till 4-yyyy

Just a thought,

Cor
 
Cor said:
I thought that if there was one who knows a lot of dates it was
you. \\\
CInt((Now.Month + 2) / 3).ToString & "-" & Now.Year
////

Would give your result I thought.

Yep, even without select case.. :-/
 
Back
Top