Excel date to Numbers text format troubles

I've been sent an Excel .xls document which I'm opening in Numbers '09 (2.1).


The spreadsheet has a date column which I need to be in text format as dd/mm/yyyy. I expected the original Excel document to have the dates already in text format but Numbers says the fields are 'Custom' and shows the dates in US format: 11/04/2011, even although my Mac is set to UK format. No matter, I can set the cells to text format, however that results in the date being shown as 04/11/00002011.


Where did those extra zeros in the year come from!?


How can I reformat the dates to the dd/mm/yyyy format as text?


I've tried a couple of formula to create a new column


=Year(A1)


for example and I think I could recreate the date like that, but the cell must be text format.


DG

MacBook Pro, Mac OS X (10.7.2)

Posted on Nov 4, 2011 3:28 AM

Reply
10 replies

Nov 4, 2011 7:13 AM in response to David Gordon

DG,


There may be a formatting option for this that I'm not aware of, but I can give you the equation that I think does what you are looking for. You're on the right path, by the way.


User uploaded file


In column A is a Date Value, properly formatted on my system. In column C is a mm/dd/yyyy representation created by this formula:


=DAY(A)&"/"&MONTH(A)&"/"&YEAR(A)


I have not altered the default alignment, so the Date Value is right aligned and the Text String formula result is left aligned.


Regards,


Jerry

Nov 4, 2011 8:08 AM in response to David Gordon

David Gordon wrote:


How do you make the text cell show the calculation result and not the formula? All I see in the cell is the formula. Becasue the cell is formatted as text?


Thanks


DG

Yes, exactly. That's, in fact, how we go about seeing an entire table of formulas. We temporarily change the whole table to Text format and all we see is the formulas. Having text operators in the formula assures that the result will be treated as text even when formatted as Automatic.


Jerry

Nov 5, 2011 2:43 AM in response to Jerrold Green1

Thanks again Jerry.


Copying the 'original' date coulmn as suggested does give me a new 'Text' formatted column. That's good!


However the original column is opening with the dates in US style mm/dd/yyyy. I need my new date column to show them in dd/mm/yyyy style. I can change the style of the dates in the original column to show dd/mm/yyyy but when copied to the new column I end up with the style 5 Nov 2011.


The original Excel document was meant to have the date column formatted as text so I'm shouting the the provider to do so. If they don't I may need to find a way of converting the date to text as part of the AppleScript which the spreadseet will be running through.



DG

Nov 5, 2011 2:56 AM in response to David Gordon

You got the extraneous zeros because you applied the format text to your cells.

When I want to convert dates in strings, I don't apply this scheme.

I use tghe formula :

=""&ref_to_cell_with_date.

User uploaded file

I use this tip in a lot of documents because it's the easiest way to treat date values with AppleScript (it drop the UTC and Daylight offset).


Yvan KOENIG (VALLAURIS, France) samedi 5 novembre 2011 10:55:48

iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2

My iDisk is : <http://public.me.com/koenigyvan>

Please : Search for questions similar to your own before submitting them to the community



Nov 5, 2011 3:42 AM in response to David Gordon

It's normal and Jerrold explained you what to do.


Assuming that original date is in B2

Insert the formula =""&B2 in the cell C2

If you remove the column B, the formula is no longer able to know what it must concatenate to the nil string "".

Before removing the column B, you must select the cells containing the formulas,

Copy to clipboard

Paste Values.


Converting the dates on themselves with an AppleScript is complicated.

When AppleScript extract the value of a cell containing the date 01/01/2011 it receive the value

01/01/2011 + UTC offset + Daylight offset.



tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1

set {date1, date2} to {value of cell "B9", value of cell "B10"}


--> {date "mardi 1 novembre 2011 01:00:00", date "jeudi 10 novembre 2011 01:00:00"}

set {value of cell "B9", value of cell "B10"} to {date1 as text, date2 as text}

end tell

If I ran it last week (Daylight saving active), I would got:


tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1

set {date1, date2} to {value of cell "B9", value of cell "B10"}


--> {date "mardi 1 novembre 2011 02:00:00", date "jeudi 10 novembre 2011 02:00:00"}

set {value of cell "B9", value of cell "B10"} to {date1 as text, date2 as text}

end tell


If the cell B9 was containing my birthday : 31/12/1943 23:59

The result would be 01/01/1944 01:59 or 01/01/1944 02:59 according to the date where I trigger the script.


In the forum MacScripter.net, Nigel Garvey gave a script getting rid of this annoying behavior but it's really complicated.

This is why I use the concatenate scheme.

From my point of view, the easiest scheme is do that and hide the column receiving the imported dates.

This way you have nothing to change when you import a new set of datas. The "Excel dates" will fill the hidden cells and you will get the wanted one in the column hosting the formulas.



PS, run the script in the USA to see how the dates are extracted for you.


Yvan KOENIG (VALLAURIS, France) samedi 5 novembre 2011 11:41:19

iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2

My iDisk is : <http://public.me.com/koenigyvan>

Please : Search for questions similar to your own before submitting them to the community



Nov 5, 2011 6:14 AM in response to KOENIG Yvan

Here is the script required to peek dates from Numbers then poke them in Numbers.


--{code}

(*

Apply this script to a Numbers table containing :

B2 : 1943/12/31 23:59

B3 : 1789/07/14

B4 : 2010/01/01 00:12

B5 : = NOW()

*)


set myTimeZone to (do shell script ("/usr/bin/perl -le 'print( readlink(\"/etc/localtime\") =~m{zoneinfo/(.*)} )' ")) -- Perl code by Mark J. Reed.


tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1

repeat with r from 2 to 5

set thenumbersdate to value of cell r of column 2

set value of cell r of column 3 to thenumbersdate as text

set thenumbersdate to my TZtoGMT(thenumbersdate, myTimeZone)

tell cell r of column 4

set format to text

set value to thenumbersdate as text

end tell

tell cell r of column 5

set format to text

set value to short date string of thenumbersdate

end tell

end repeat

end tell


--=====

(*

set myTimeZone to (do shell script ("/usr/bin/perl -le 'print( readlink(\"/etc/localtime\") =~m{zoneinfo/(.*)} )' ")) -- Perl code by Mark J. Reed.

set thenumbersdate to my TZtoGMT(thenumbersdate, myTimeZone)

*)


(*

Handlers by Nigel GARVEY

http://macscripter.net/viewtopic.php?id=36449

*)

(* Convert an ISO-format date string to an AppleScript date. *)

on isotToDate(isot)

set n to (text 1 thru 8 of isot) as integer

set ASDate to (current date)

tell ASDate to set {day, year, its month, day} to {1, n div 10000, n mod 10000 div 100, n mod 100}

if ((count isot) > 8) then

set n to (text 10 thru 15 of isot) as integer

set ASDate's time to n div 10000 * hours + n mod 10000 div 100 * minutes + n mod 100

end if


return ASDate

end isotToDate


--=====


(* Transpose an AppleScript date/time from the given time zone to GMT. *)

on TZtoGMT(TZDate, TZ)


-- The difference between TZDate when it's local and the GMT date we want is usually


-- the same as the difference between the local date when TZDate is GMT and TZDate itself …

set GMTDate to TZDate - (GMTtoTZ(TZDate, TZ) - TZDate)


-- … but not around the time the clocks go forward. If the GMT obtained doesn't reciprocate to TZDate,


-- shift to a nearby local date where the above DOES work, get a new GMT, unshift it by the same amount.

set testDate to GMTtoTZ(GMTDate, TZ)

if (testDate is not TZDate) then

if (GMTDate > testDate) then -- "Clocks forward" is towards GMT.

set shift to GMTDate - testDate

else -- "Clocks forward" is away from GMT.

set shift to -days

end if

set nearbyDate to TZDate + shift

set GMTDate to nearbyDate - (GMTtoTZ(nearbyDate, TZ) - nearbyDate) - shift

end if


return GMTDate

end TZtoGMT


--=====


(* Transpose an AppleScript date/time from GMT to the given time zone. *)

on GMTtoTZ(GMTDate, TZ)


-- Subtract date "Thursday 1 January 1970 00:00:00" from the GMT date. Result in seconds, as text.

copy GMTDate to date19700101

tell date19700101 to set {year, its month, day, time} to {1970, 1, 1, 0}

set eraTime to (GMTDate - date19700101)

if (eraTime > 99999999) then

set eraTime to (eraTime div 100000000 as text) & text 2 thru 9 of (100000000 + eraTime mod 100000000 as integer as text)

else if (eraTime < -99999999) then

set eraTime to (eraTime div 100000000 as text) & text 3 thru 10 of (-100000000 + eraTime mod 100000000 as integer as text)

else

set eraTime to eraTime as text

end if


return isotToDate(do shell script ("TZ='" & TZ & "' /bin/date -r " & eraTime & " +%Y%m%dT%H%M%S"))

end GMTtoTZ


--=====

--{code}


User uploaded file


Yvan KOENIG (VALLAURIS, France) samedi 5 novembre 2011 14:14:26

iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2

My iDisk is : <http://public.me.com/koenigyvan>

Please : Search for questions similar to your own before submitting them to the community



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Excel date to Numbers text format troubles

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.