Solved

Format date and time - 0001

Posted on 2010-08-16
9
343 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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
 
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 81

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

778 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