Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Need a method to extract the Date from a cell to a new cel

Need a method to extract the Date from a cell to a new
cel. the curent value of two cells a
10/31/2003 3:34:48 PM
8/22/2003 7:29:08 PM

While I am at it, how do I extract the time also
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Need a method to extract the Date from a cell to a new cel

Put the dates into column A and run this code

Private Sub CommandButton1_Click()
a = 1
Do While Range("A" & a) < ""

For x = 1 To Len(Range("A" & a))

If Mid(Range("A" & a), x, 1) = "/" Then y = y + 1
If y = 2 Then Exit For

Next x
y = 0
Dim z As Integer
Range("c" & a) = Left(Range("a" & a), x + 4)
z = Len(Range("A" & a))
Range("e" & a) = Right(Range("a" & a), z - x - 4)

a = a + 1
Loop

End Sub






"Paul" wrote in message
...
Need a method to extract the Date from a cell to a new
cel. the curent value of two cells a
10/31/2003 3:34:48 PM
8/22/2003 7:29:08 PM

While I am at it, how do I extract the time also



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Need a method to extract the Date from a cell to a new cel

Excel stores dates as whole numbers and times as decimal fractions. To extract date and time from a cell you need to separate the
whole number and the fractional part.

If you want formulas for this and assuming that your date/time value is in A1:

=INT(A1) for the date part
=MOD(A1, 1) for the time part

If you want VBA code

Range("B1").Value = Int(Range("A1").Value 'for the date
Range("B2").Value = Range("A1").Value - Int(Range("A1").Value 'for the time part

There is a Mod operator in VBA, but it does not return fractional values.

--

John Green - Excel MVP
Sydney
Australia


"Paul" wrote in message ...
Need a method to extract the Date from a cell to a new
cel. the curent value of two cells a
10/31/2003 3:34:48 PM
8/22/2003 7:29:08 PM

While I am at it, how do I extract the time also



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Need a method to extract the Date from a cell to a new cel

Not forgetting the closing parentheses on the Int function, as I did.

--

John Green - Excel MVP
Sydney
Australia


"John Green" wrote in message ...
Excel stores dates as whole numbers and times as decimal fractions. To extract date and time from a cell you need to separate the
whole number and the fractional part.

If you want formulas for this and assuming that your date/time value is in A1:

=INT(A1) for the date part
=MOD(A1, 1) for the time part

If you want VBA code

Range("B1").Value = Int(Range("A1").Value 'for the date
Range("B2").Value = Range("A1").Value - Int(Range("A1").Value 'for the time part

There is a Mod operator in VBA, but it does not return fractional values.

--

John Green - Excel MVP
Sydney
Australia


"Paul" wrote in message ...
Need a method to extract the Date from a cell to a new
cel. the curent value of two cells a
10/31/2003 3:34:48 PM
8/22/2003 7:29:08 PM

While I am at it, how do I extract the time also





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default Need a method to extract the Date from a cell to a new cel

This works too:

=DATE(YEAR(A1),MONTH(A1),DAY(A1))
=TIME(HOUR(A1),MINUTE(A1),SECOND(A1))

Shockley





"Paul" wrote in message
...
Need a method to extract the Date from a cell to a new
cel. the curent value of two cells a
10/31/2003 3:34:48 PM
8/22/2003 7:29:08 PM

While I am at it, how do I extract the time also





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Need a method to extract the Date from a cell to a new cel

Good point. It's probably more readily understood by most users than my approach.

--

John Green - Excel MVP
Sydney
Australia


"shockley" wrote in message ...
This works too:

=DATE(YEAR(A1),MONTH(A1),DAY(A1))
=TIME(HOUR(A1),MINUTE(A1),SECOND(A1))

Shockley





"Paul" wrote in message
...
Need a method to extract the Date from a cell to a new
cel. the curent value of two cells a
10/31/2003 3:34:48 PM
8/22/2003 7:29:08 PM

While I am at it, how do I extract the time also





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
extract date from last cell puiuluipui Excel Discussion (Misc queries) 5 September 14th 09 05:33 PM
extract year from the date in a cell DKY Excel Worksheet Functions 7 March 17th 06 07:07 PM
extract name when a date in another cell gets near cityfc Excel Worksheet Functions 5 November 10th 05 01:20 AM
extract name when a date in another cell gets near cityfc Excel Discussion (Misc queries) 1 November 9th 05 07:40 PM
Extract date from cell Eric Excel Worksheet Functions 3 November 4th 04 06:37 PM


All times are GMT +1. The time now is 01:20 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"