#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Date & Time Format

I export data that includes the date & time. The data is exported directly
into Excel with the date & time as follows: dd.mm.yyy hh:mm. This presents
no great problem because a simple find & replace on the column gives me
dd/mm/yyyy hh:mm which Excel recognises as a date and my formulas work OK. I
thought a Macro would save me some time, however, no amount of trying
prevents the Macro from formating the date mm/dd/yyyy hh:mm. I think I have
tried all the formatting options (including checking the system date and
time) and even tried including the formatting in the Macro and editing the
date in VBE. But............. it will insist on giving me the month, day and
year in that order. I thought it may be Excel 2000 (at work) but it also
happens in Excel 2003 (at home). Has anyone any thoughts please?
--
Glenn
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Date & Time Format

Say A1 contains:

25.12.2008 09:30

In another cell enter:
=DATE(MID(A1,7,4),MID(A1,4,2),LEFT(A1,2))+TIME(MID (A1,12,2),RIGHT(A1,2),0)
and format:
Format Cells... . Number Custom dd/mm/yyyy hh:mm

This will display:
25/12/2008 09:30


--
Gary''s Student - gsnu200772


"Brampton76" wrote:

I export data that includes the date & time. The data is exported directly
into Excel with the date & time as follows: dd.mm.yyy hh:mm. This presents
no great problem because a simple find & replace on the column gives me
dd/mm/yyyy hh:mm which Excel recognises as a date and my formulas work OK. I
thought a Macro would save me some time, however, no amount of trying
prevents the Macro from formating the date mm/dd/yyyy hh:mm. I think I have
tried all the formatting options (including checking the system date and
time) and even tried including the formatting in the Macro and editing the
date in VBE. But............. it will insist on giving me the month, day and
year in that order. I thought it may be Excel 2000 (at work) but it also
happens in Excel 2003 (at home). Has anyone any thoughts please?
--
Glenn

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,480
Default Date & Time Format

Hi Glenn

The following seemed to work for me

Sub test()

Dim c As Range
For Each c In Range("G2:G13")
c.Value = Format(Replace(c, ".", "/"), "dd/mm/yyyy hh:mm")
Next

End Sub


--
Regards
Roger Govier

"Brampton76" wrote in message
...
I export data that includes the date & time. The data is exported
directly
into Excel with the date & time as follows: dd.mm.yyy hh:mm. This
presents
no great problem because a simple find & replace on the column gives me
dd/mm/yyyy hh:mm which Excel recognises as a date and my formulas work OK.
I
thought a Macro would save me some time, however, no amount of trying
prevents the Macro from formating the date mm/dd/yyyy hh:mm. I think I
have
tried all the formatting options (including checking the system date and
time) and even tried including the formatting in the Macro and editing the
date in VBE. But............. it will insist on giving me the month, day
and
year in that order. I thought it may be Excel 2000 (at work) but it also
happens in Excel 2003 (at home). Has anyone any thoughts please?
--
Glenn


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Date & Time Format

Many thanks. It converted the "." to "/" OK but the format remains
mm/dd/yyyy. I am wondering if it is a deeper problem for me. The format
cell screen allows me to select dd/mm/yyyy as a format but in the example
screen it shows mm/dd/yyyy. All very odd!
--
Glenn


"Roger Govier" wrote:

Hi Glenn

The following seemed to work for me

Sub test()

Dim c As Range
For Each c In Range("G2:G13")
c.Value = Format(Replace(c, ".", "/"), "dd/mm/yyyy hh:mm")
Next

End Sub


--
Regards
Roger Govier

"Brampton76" wrote in message
...
I export data that includes the date & time. The data is exported
directly
into Excel with the date & time as follows: dd.mm.yyy hh:mm. This
presents
no great problem because a simple find & replace on the column gives me
dd/mm/yyyy hh:mm which Excel recognises as a date and my formulas work OK.
I
thought a Macro would save me some time, however, no amount of trying
prevents the Macro from formating the date mm/dd/yyyy hh:mm. I think I
have
tried all the formatting options (including checking the system date and
time) and even tried including the formatting in the Macro and editing the
date in VBE. But............. it will insist on giving me the month, day
and
year in that order. I thought it may be Excel 2000 (at work) but it also
happens in Excel 2003 (at home). Has anyone any thoughts please?
--
Glenn


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Date & Time Format

Many thanks for all your help. I can only imagine there was some 'finger
trouble' on my part, because it works a treat now.
--
Glenn


"Roger Govier" wrote:

Hi Glenn

The following seemed to work for me

Sub test()

Dim c As Range
For Each c In Range("G2:G13")
c.Value = Format(Replace(c, ".", "/"), "dd/mm/yyyy hh:mm")
Next

End Sub


--
Regards
Roger Govier

"Brampton76" wrote in message
...
I export data that includes the date & time. The data is exported
directly
into Excel with the date & time as follows: dd.mm.yyy hh:mm. This
presents
no great problem because a simple find & replace on the column gives me
dd/mm/yyyy hh:mm which Excel recognises as a date and my formulas work OK.
I
thought a Macro would save me some time, however, no amount of trying
prevents the Macro from formating the date mm/dd/yyyy hh:mm. I think I
have
tried all the formatting options (including checking the system date and
time) and even tried including the formatting in the Macro and editing the
date in VBE. But............. it will insist on giving me the month, day
and
year in that order. I thought it may be Excel 2000 (at work) but it also
happens in Excel 2003 (at home). Has anyone any thoughts please?
--
Glenn




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Date & Time Format

And finally....... If I format the cells as dd/mm/yyyy hh:mm and run your
routine I get mm/dd/yyyy hh:mm. However, If I alter your routine to replace
as dd/mmm/yyyy hh:mm I get dd/mm/yyyy hh:mm - all a bit odd, but I am where I
need to be. Again, many thanks for your help and guidance.
--
Glenn


"Roger Govier" wrote:

Hi Glenn

The following seemed to work for me

Sub test()

Dim c As Range
For Each c In Range("G2:G13")
c.Value = Format(Replace(c, ".", "/"), "dd/mm/yyyy hh:mm")
Next

End Sub


--
Regards
Roger Govier

"Brampton76" wrote in message
...
I export data that includes the date & time. The data is exported
directly
into Excel with the date & time as follows: dd.mm.yyy hh:mm. This
presents
no great problem because a simple find & replace on the column gives me
dd/mm/yyyy hh:mm which Excel recognises as a date and my formulas work OK.
I
thought a Macro would save me some time, however, no amount of trying
prevents the Macro from formating the date mm/dd/yyyy hh:mm. I think I
have
tried all the formatting options (including checking the system date and
time) and even tried including the formatting in the Macro and editing the
date in VBE. But............. it will insist on giving me the month, day
and
year in that order. I thought it may be Excel 2000 (at work) but it also
happens in Excel 2003 (at home). Has anyone any thoughts please?
--
Glenn


  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Date & Time Format

You may want to format the cells in an unambiguous format.

I like: mmmm dd, yyyy hh:mm:ss

Then check to see if the converted values actually represent the dates from the
original source.

I'm wondering if 01.02.2008 12:30
is being converted to: January 2, 2008 12:30
or if it's getting converted to: February 1, 2008 12:30

Sometimes, just because the results look like dates doesn't mean that they are
the correct dates.

Brampton76 wrote:

And finally....... If I format the cells as dd/mm/yyyy hh:mm and run your
routine I get mm/dd/yyyy hh:mm. However, If I alter your routine to replace
as dd/mmm/yyyy hh:mm I get dd/mm/yyyy hh:mm - all a bit odd, but I am where I
need to be. Again, many thanks for your help and guidance.
--
Glenn

"Roger Govier" wrote:

Hi Glenn

The following seemed to work for me

Sub test()

Dim c As Range
For Each c In Range("G2:G13")
c.Value = Format(Replace(c, ".", "/"), "dd/mm/yyyy hh:mm")
Next

End Sub


--
Regards
Roger Govier

"Brampton76" wrote in message
...
I export data that includes the date & time. The data is exported
directly
into Excel with the date & time as follows: dd.mm.yyy hh:mm. This
presents
no great problem because a simple find & replace on the column gives me
dd/mm/yyyy hh:mm which Excel recognises as a date and my formulas work OK.
I
thought a Macro would save me some time, however, no amount of trying
prevents the Macro from formating the date mm/dd/yyyy hh:mm. I think I
have
tried all the formatting options (including checking the system date and
time) and even tried including the formatting in the Macro and editing the
date in VBE. But............. it will insist on giving me the month, day
and
year in that order. I thought it may be Excel 2000 (at work) but it also
happens in Excel 2003 (at home). Has anyone any thoughts please?
--
Glenn



--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Date & Time Format

Did you really mean: dd.mm.yyyy hh:mm (with a 4 digit year)?

The first thing I would do is reformat that data in a nice unambiguous date
format: mmmm dd, yyyy hh:mm:ss

You may find that some of your data was imported as real dates--but not imported
correctly. But with the dots as the separator, I would guess that you would be
ok.

I'd use a macro like this (after selecting the range to fix):

Option Explicit
Sub Macro1()

Dim myRng As Range
Dim myStr As String
Dim myCell As Range

Set myRng = Nothing
On Error Resume Next
Set myRng = Intersect(Selection, _
Selection.Cells.SpecialCells(xlCellTypeConstants, _
xlTextValues))
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "Select some cells with values"
Exit Sub
End If

For Each myCell In myRng.Cells
'dd.mm.yyyy hh:mm
With myCell
myStr = .Value
.Value = DateSerial(Mid(myStr, 7, 4), _
Mid(myStr, 4, 2), _
Left(myStr, 2)) _
+ TimeSerial(Mid(myStr, 12, 2), _
Right(myStr, 2), 0)
.NumberFormat = "mm/dd/yyyy hh:mm"
End With
Next myCell
End Sub



Brampton76 wrote:

I export data that includes the date & time. The data is exported directly
into Excel with the date & time as follows: dd.mm.yyy hh:mm. This presents
no great problem because a simple find & replace on the column gives me
dd/mm/yyyy hh:mm which Excel recognises as a date and my formulas work OK. I
thought a Macro would save me some time, however, no amount of trying
prevents the Macro from formating the date mm/dd/yyyy hh:mm. I think I have
tried all the formatting options (including checking the system date and
time) and even tried including the formatting in the Macro and editing the
date in VBE. But............. it will insist on giving me the month, day and
year in that order. I thought it may be Excel 2000 (at work) but it also
happens in Excel 2003 (at home). Has anyone any thoughts please?
--
Glenn


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert date + time text format to date format Paul Ho Excel Worksheet Functions 2 May 22nd 07 05:47 PM
format date time IT05 Excel Worksheet Functions 5 February 16th 06 10:19 PM
date time format nomi Excel Discussion (Misc queries) 3 September 8th 05 08:59 AM
how do I format cells to change date and time to just date bondam Excel Discussion (Misc queries) 3 July 3rd 05 01:10 PM
Remove time from a date and time field? Format removes the displa. oaoboc Excel Worksheet Functions 1 February 16th 05 07:20 PM


All times are GMT +1. The time now is 04:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"