Solved

Format date and time - 0001

Posted on 2010-08-16
9
321 Views
Last Modified: 2012-05-10
Hello all,

In my excel .Cells(i, 11), i have a date and time format "201008160100" for example. Year:2010, month:08, Day:10, Hour:01, Min:00.

I need to have in cell 13 the value from .Cells(i, 11) but remove 1 minute.

The result of the example "201008160100" would be "201008160059"

Thanks for your help


.Cells(i, 13) = .Cells(i, 11) - "0001"

Open in new window

0
Comment
Question by:Wilder1626
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33445173
=TEXT(DATE(LEFT(A1,4),MID(A1,5,2),MID(A1,7,2))+TIME(MID(A1,9,2),MID(A1,11,2),0)-TIME(0,1,0),"yyyymmddhhmm")
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 33445187
Try this function....

    Function subtractMinute(dateString As String) As String
        Dim timeString As String
        timeString = Right(dateString, 4)
   
        Dim timeVal As Date
        timeVal = TimeSerial(Left(timeString, 2), Right(timeString, 2), 0)
   
        Dim newDateString As String
        newDateString = Left(dateString, 8) & Format(DateAdd("n", -1, timeVal), "hhmm")
   
        subtractMinute = newDateString
    End Function

Use it like this....

    MsgBox subtractMinute("201008160100")

Wayne
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 33445197
For that matter, you can use it as a worksheet formula as well.

Wayne
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 33445199
Hello,

I have a syntax error:
.Cells(i, 13) = TEXT(DATE(LEFT(A1,4),MID(A1,5,2),MID(A1,7,2))+TIME(MID(A1,9,2),MID(A1,11,2),0)-TIME(0,1,0),"yyyymmddhhmm")
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 33445232
s = .Cells(i, 11)
s = Format(DateAdd("n", -1, DateSerial(Left(s, 4), Mid(s, 5, 2), Mid(s, 7, 2)) + TimeSerial(Mid(s, 9, 2), Mid(s, 11, 2), 0)), "yyyymmddhhmm")
.Cells(i, 13) = s
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33445246
webtubbs - would your code handle taking 1 minute off 0000? first day of year?
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 33445321
Just as an alternative:
=TEXT(TEXT(A1,"0000""-""00""-""00 00"":""00")*1-TIME(0,0,1),"yyyymmddhhmm")
0
 
LVL 80

Expert Comment

by:byundt
ID: 33450364
You can shorten Rory's formula using the backslash to indicate literals:
=TEXT(TEXT(A1,"0000\-00\-00 00\:00")-1/1440,"yyyymmddhhmm")
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 33451243
Thanks to everybody.

Now it works.

Thanks again :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now