简体   繁体   中英

Convert date as text “YYYY:DD:MM hh:mm:ss” to real date

如何将以文本“ YYYY:DD:MM hh:mm:ss”给出的日期转换为格式为YYYY.MM.DD hh:mm:ss的日期?

The worksheet formula solution would involve the LEFT function , MID function and RIGHT function .

=DATE(LEFT(A1, 4), MID(A1, 9, 2), MID(A1, 6, 2))+TIME(MID(A1, 12, 2), MID(A1, 15, 2), RIGHT(A1, 2))

日期文字解析

Format the cell ( Ctrl + 1 ) with a Numbers ► Custom ► Type: of yyyy.mm.dd hh:mm:ss .

Those functions work exactly the same way in VBA. The DATE function and TIME function would be DateSerial and TimeSerial .

I just had the same problem and my file has 400,000+ rows with text in this format : yyyy-mm-dd hh:mm:ss. The custom date format did not work at first, but you can use =VALUE(text) and then apply the custom cell format of your choice. Somehow Excel knows your text is a date with an equivalent number butwill not let you change the format otherwise.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM