PDA

View Full Version : Solved: Keep date look in the result of a formula



danlu
02-08-2008, 07:21 AM
Hi,

I have a column (for ex column B) with dates (actually it doesn't matter if the cells have date format or something else the important thing is that it is displayed with a date look, in this case for ex 2007-01-10 ( that is the 10th of January 2007)

To these dates I want to add ' on both sides of the date so it looks like '2007-01-10', to achieve this I have tried to use the concatenate like this:

=concatenate ("'";B2;"'")

But Excel always convert my date value into a number format so the result looks something like this: '39092'

Which causes me trobles since I want to copy this data into another program (that doesn't have anything to do with Excel) where I want to display all dates surounded with ' on both sides.

Any suggestions are welcome

rory
02-08-2008, 07:51 AM
You can use:
=TEXT(B2;"'yyyy-mm-dd'")

RichardSchollar
02-08-2008, 07:53 AM
Hi

Try:

=CONCATENATE("'";TEXT(B2,"yyyy-mm-dd");"'")

Richard

EDIT: ...or Rory's which is much simpler...

danlu
02-11-2008, 06:35 AM
Hi
I have tried =TEXT(B5;"yyyymmdd") which gives me the result:
yyyy0031
I guess I do something wrong with the date format since it doesn't seem to understand the month value (should be 12 and not 00)and cannot interpret the year.

Bob Phillips
02-11-2008, 06:41 AM
It is because you have Swedish Excel

use

=TEXT(B5;"xxxxwwwuu")

wher x is the first letter for the Swedish word for year, w - month,and u - day.

Bob Phillips
02-11-2008, 06:46 AM
I think it should be

=TEXT(B5;"aaaammdd")

Bob Phillips
02-11-2008, 06:47 AM
To find out for sure, in the VBIDE immediate window enter

Activecell.Formula="=TEXT(B5,""yyyymmdd"")"

and see what you get in the activecell.

danlu
02-11-2008, 09:09 AM
Hi thanks for your tip about the Swedish format.
With the following I have managed to get the year and day correct:
=TEXT(B3;"????-mm-dd")

For the month it works from jan to sep (that is from 01 to 09) but when I try with 10 (oct),11 (nov) or 12 (dec) it returns month = 00.

In which window in IDE should I try your code (should it be via INSERT /MODULE ? )

Bob Phillips
02-11-2008, 09:27 AM
Go to the VBIDE (Alt-F11), open the immediate window (Ctrl-G), and type it in there.

danlu
02-12-2008, 12:42 AM
Hi,

the result was yyyy0000

What does that indicate?

Bob Phillips
02-12-2008, 11:26 AM
What was the total output in the cell?