PC Review


Reply
Thread Tools Rate Thread

Convert Date/time to date only in vba

 
 
=?Utf-8?B?Sm9uYXRoYW4=?=
Guest
Posts: n/a
 
      15th Jun 2007
Hi,

I have a dataset I extract from another tool and import into Excel. The
dates from this toolset are in dd/mm/yyyy hrs/min/sec format, I need to
programmatically change this to be just dd/mm/yyyy format in the columns
containing the dates. I've tried looping through and using datevalue() and
just trimming the contents to only the first 10 characters but neither work
for me, can anyone send me a snippet of code to get the job done?

Regards

Jonathan
 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      15th Jun 2007
Jonathan,
Date/time is stored as a double in Excel; the whole number part is the date
and the fractional part is the time. So if you remove the decimal part, you
have a date only - or rather a midnight on that day.

=INT(A1)

NickHK

"Jonathan" <(E-Mail Removed)> wrote in message
news:938AD718-1E1E-4185-A728-(E-Mail Removed)...
> Hi,
>
> I have a dataset I extract from another tool and import into Excel. The
> dates from this toolset are in dd/mm/yyyy hrs/min/sec format, I need to
> programmatically change this to be just dd/mm/yyyy format in the columns
> containing the dates. I've tried looping through and using datevalue() and
> just trimming the contents to only the first 10 characters but neither

work
> for me, can anyone send me a snippet of code to get the job done?
>
> Regards
>
> Jonathan



 
Reply With Quote
 
=?Utf-8?B?TWlrZSBI?=
Guest
Posts: n/a
 
      15th Jun 2007
Jonathan,

Try this with the range altered to suit:-

Sub stantial()
Dim myRange As Range
Set myRange = Worksheets("Sheet1").Range("A1:A1000") '<======Alter to suit
For Each c In myRange
c.Value = Int(c.Value)
Next
End Sub

Mike

"Jonathan" wrote:

> Hi,
>
> I have a dataset I extract from another tool and import into Excel. The
> dates from this toolset are in dd/mm/yyyy hrs/min/sec format, I need to
> programmatically change this to be just dd/mm/yyyy format in the columns
> containing the dates. I've tried looping through and using datevalue() and
> just trimming the contents to only the first 10 characters but neither work
> for me, can anyone send me a snippet of code to get the job done?
>
> Regards
>
> Jonathan

 
Reply With Quote
 
=?Utf-8?B?Sm9uYXRoYW4=?=
Guest
Posts: n/a
 
      15th Jun 2007
I'll give it a try, I managed to get it sorted using a clunky loop to convert
the dates to the decimal number format and then change the cell format to
dd/mm/yyyy, it also allows me to deal with the cells that have the text
<void> instead of a valid date from the other tools output, still falls over
as soon as it encounters a completely blank cell but this only occurs at the
end of the imported data ;-)

"Mike H" wrote:

> Jonathan,
>
> Try this with the range altered to suit:-
>
> Sub stantial()
> Dim myRange As Range
> Set myRange = Worksheets("Sheet1").Range("A1:A1000") '<======Alter to suit
> For Each c In myRange
> c.Value = Int(c.Value)
> Next
> End Sub
>
> Mike
>
> "Jonathan" wrote:
>
> > Hi,
> >
> > I have a dataset I extract from another tool and import into Excel. The
> > dates from this toolset are in dd/mm/yyyy hrs/min/sec format, I need to
> > programmatically change this to be just dd/mm/yyyy format in the columns
> > containing the dates. I've tried looping through and using datevalue() and
> > just trimming the contents to only the first 10 characters but neither work
> > for me, can anyone send me a snippet of code to get the job done?
> >
> > Regards
> >
> > Jonathan

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert text date to date/time Nico Microsoft Access Queries 3 27th May 2008 04:47 PM
Convert Date To Time Back To Date Lovely Angel For You Microsoft Access 4 11th May 2007 09:59 PM
How do I convert a date&time (yyyy-mm-dd hh:mm:ss) to date only? =?Utf-8?B?V2VzbGV5IEFjY2VsbGVudA==?= Microsoft Excel Worksheet Functions 7 1st Dec 2005 07:59 PM
Convert date to length of time in months from set date =?Utf-8?B?TUpVSw==?= Microsoft Excel Worksheet Functions 1 19th Mar 2005 06:31 PM
Convert Date Time in Spreadsheet Column to Date only Genga Microsoft Excel Programming 1 8th Jun 2004 08:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:44 AM.