简体   繁体   中英

How to convert date format in Excel

When I pull out data using SQL query and copy and paste the date to excel it automatically bring AM or PM right next to original data.

For example:

2021-04-11 11:45:00.000   (SQL data)  -->  2021-04-11  11:45:00 **AM**

There an Excel file where we filed up raw data for the pivot table. Thus, I need to match with the previous raw data format and I lost my way..

To store raw data, there are few steps as below.

  1. split date date into date and time basis. (for hour columns, we use 'hh' format). ex) 1:15:00 PM appeared as 13.
  2. convert date data to text format so that could extract month out of it.
  3. copy hour data that I pull out from the 1st step and transform to text. into hh:mm:ss and changed to text. so I could extract min and other info. (for minute data I will use MIN function since it is text)

There are few errors when I update data since there is differences in default setting by computers. and I need to follow the above steps and data format. the error that I am facing for each steps are.

  1. After converting date data into text, I can't not read month information using MONTH() function. The date data that I have for example is '2021-04-01' and it returns 0. I used:: =MONTH([@date])

  2. When I tried to copy 'time dates' and pasted to the other column and to convert TEXT format. it returns me 1:15:00 PM in text form. If I covert the data to 13:15:00 and convert it, I get an error. I used =TEXT(your_calc_formula,"hh:mm:ss")

Please help me out. thanks in advance.. !!

You say, 2021-04-11 11:45:00.000 (SQL data) --> 2021-04-11 11:45:00 AM. This tells me that the SQL expression is a "True" date. You should keep it that way. Don't convert it to text.

The True date is a number, in this case 44297.4895833333. The format 2021-04-11 11:45:00 AM is determined by the cell to which the True date was pasted. You can change that cell's format to whatever you like. The likely source of "AM" is your Windows International Setting for Time values, meaning the worksheet to which you paste the SQL data has a cell format of "General" and Excel converts that to Date/Time when it receives the True date, using the default taken from Windows in the absence of another idea.

From the date value, 44297.4895833333, you can extract the month, the day, the year and the time. Each of these you can display the way you want. In fact, Format(44297.4895833333, "dddd") will display "Sunday". Format(CDbl(CDate("2021-04-11 11:45:00 AM")), "mmmm") will display "April". So, you may not have to extract the numbers. But you must stay aware of the difference between the value in the cell and the display on its surface.

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