+ Reply to Thread
Results 1 to 8 of 8

Replacing . with : in date time value changes the date

  1. #1
    Forum Contributor
    Join Date
    10-30-2014
    Location
    England
    MS-Off Ver
    2007 / 365
    Posts
    279

    Replacing . with : in date time value changes the date

    I have a column of dates and times, all formatted as dd/mm/yyyy hh:mm

    I am trying to write some code to amend the data when a user enters the time in the format of hh.mm instead of hh:mm

    Strangely though, I am finding that running my code causes excel to switch around the dd/mm part of the data...

    Please Login or Register  to view this content.
    If I run this on a cell containing 07/05/2021 09.15 then it changes to 05/07/2021 09:15

    However, the date format set for the cell remains dd/mm/yyyy hh:mm, plus if I manually use the Find/Replace dialog to make the same replacement it doesn't switch around the dd/mm

    Might be something incredibly obvious, but I can't work out why it's happening.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Replacing . with : in date time value changes the date

    What is 07/05/2021 meant to be?

    The 7th May or the 5th July?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    10-30-2014
    Location
    England
    MS-Off Ver
    2007 / 365
    Posts
    279

    Re: Replacing . with : in date time value changes the date

    The date format is dd/mm/yyyy, so 7th May

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,852

    Re: Replacing . with : in date time value changes the date

    I suspect that the first entry, 07/05/2021 09.15, is actually a text value that just happens to look like a date and time, and that when you do your replacement then Excel tries to make sense of it and uses your regional settings to conclude how to format the result.

    Hope this helps.

    Pete

  5. #5
    Forum Contributor
    Join Date
    10-30-2014
    Location
    England
    MS-Off Ver
    2007 / 365
    Posts
    279

    Re: Replacing . with : in date time value changes the date

    But the cell number format is set to dd/mm/yyyy hh:mm, and my regional settings are the same, plus why would the code cause Excel to change it but Find/Replace doesn't change it?

    Is there another way to code the replacement that might work differently?

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Replacing . with : in date time value changes the date

    Hi

    One way

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    10-30-2014
    Location
    England
    MS-Off Ver
    2007 / 365
    Posts
    279

    Re: Replacing . with : in date time value changes the date

    Thanks Richard, I'll give that a try

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Re: Replacing . with : in date time value changes the date


    Hi,

    'cause of the time included just use VBA CDate function to convert the text replacement as a Date …
    Last edited by Marc L; 05-07-2021 at 05:21 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. adding date and time and subtracting date-time2 from date-time1
    By tinkerbelle in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-22-2018, 10:05 AM
  2. Replies: 7
    Last Post: 06-19-2017, 06:10 PM
  3. Replies: 6
    Last Post: 06-09-2015, 07:37 PM
  4. Replies: 9
    Last Post: 02-15-2015, 07:32 PM
  5. Replies: 3
    Last Post: 12-19-2013, 06:49 AM
  6. Replacing the year in a date and time cell.
    By samsam in forum Excel General
    Replies: 10
    Last Post: 01-18-2011, 09:56 AM
  7. Calculating days & time left from start date/time to end date/time
    By marie in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-07-2005, 10:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1