Excel формат даты для sql

My excel sheet has the following format : dd/mm/YYYY

ex: 24/10/2010 (european format)

and my mysql needs: YYYY-mm-dd (US format)

How can I format the date in Excel to have this US format ?
I tried with cell format, but I don’t have the desired format

Regards

marc_s's user avatar

marc_s

726k174 gold badges1326 silver badges1449 bronze badges

asked Jan 27, 2011 at 13:58

yarek's user avatar

1

Here’s how you can find this Number format in Excel:

  1. Go to Format Cells and then the Number tab.
  2. Select Date
  3. Change the Locale to English (U.K.)
  4. The fifth item on the list (on my U.S. version of Excel) is the format you’re looking for.

Hope that helps!

answered Jan 27, 2011 at 14:17

Scott Cranfill's user avatar

For the hours, minutes and second

go in the custom category and enter this :

yyyy-mm-dd hh:mm:ss

answered Nov 9, 2012 at 8:02

jpprade's user avatar

jppradejpprade

3,4373 gold badges45 silver badges57 bronze badges

Use the text function — assuming that the date to be converted was in cell A1, =TEXT(A1,»YYYYMMDD») will get your data into a format that mysql will understand as a date.

answered Mar 1, 2011 at 19:03

Andrew's user avatar

AndrewAndrew

8,9818 gold badges45 silver badges59 bronze badges

There are many solutions, but I reformat the dates for mysql using this formula (assuming your date is in cell E2):

=YEAR(E2)&"-"&RIGHT(TRIM(100+MONTH(E2)),2)&"-"&RIGHT(TRIM(100+DAY(E2)),2)

Mogsdad's user avatar

Mogsdad

44.3k21 gold badges151 silver badges272 bronze badges

answered Apr 28, 2016 at 3:32

mgalka's user avatar

mgalkamgalka

1711 silver badge6 bronze badges

  • Remove From My Forums
  • Question

  • Sorry but I didn’t know which category would describe my question the best way.
    I get some data from a view in SQL Server to display it in Excel.
    The view returns a column with the type «Date», which is displayed as a normal text in Excel (like «2014-11-31»).
    I want to create a Pivot table from this raw data, so it’s important that the type of this column is really «Date».

    Do I really have to return the data as a string in the correct format (for example «31.11.2014» here in Germany)?
    I would like to give less experienced people access to the view, so solutions where users don’t have to change a lot manually are preferred (even if it’s a strange string cast).

    Thanks for your help!

Answers

  • I’ve had similar experiences, and in my case, I think the problem was that I was using MDAC from several years ago, when SQL did not have «date» and «time» data types.  When I import data directly into Excel from SQL, the «date» fields come across
    as text.  However, the middleware did recognize smalldatetime values as dates.  What I’ve done to get around this problem is to cast the dates as smalldatetime in the query that I import to Excel.  It’s a little clumsy, but it did allow date
    values to come across directly into Excel and be recognized as dates.  Worth a try, anyway.


    Doug Hudson

    • Marked as answer by

      Monday, June 30, 2014 4:03 PM

When creating SQL statements you’ll often need a date in the ISO 8601 standard format (e.g. 2010-03-26 12:34).

Of course you can change the format in Excel to show it as such, but that doesn’t give you the string you need, e.g. in an insert or update statement.

Here’s an Excel function to make an SQL date value, presuming the date value is in cell A1:

=TEXT(A1,”yyyy-mm-dd hh:MM:ss”)

This circumvents the use of complicated IF and date/time functions. Append a “Z” if you need to indicate the timezone as UTC (i.e. GMT) time.

Here’s a short VBA function to create this type of date

Function SQLDate(d)
SQLDate = WorksheetFunction.Text(d, "yyyy-mm-dd hh:MM:ss")
End Function

Put this code in a new module in your workbook to instantly start using the function in Excel like this: “=SQLDate(A1)”

SQL date in Excel

SQL date in Excel

More information:

http://en.wikipedia.org/wiki/ISO_8601

Michiel van der Blonk, software developer, trainer, writer, speedcuber, just zis guy you know….
View all posts by michiel

See more:

I have Student Attendance Excel in Which I filling attendance detail of student at last of month I upload that excel sheet in database.When uploading excel sheet I getting this error

Error Uploading all Records.Object reference not set to an instance of an object

Comments

The issue in the title does not match the error message.
Please improve your question and give relevant details, including the code block that is throwing the exception. Do not post code in comments; please press the «Improve question» button instead.


1 solution

Solution 1

Function SQLDate(d)
SQLDate = WorksheetFunction.Text(d, «yyyy-mm-dd hh:MM:ss»)
End Function

or else

if staging table is an option, you could convert Excel date to string using
TEXT(d,»dd mmmm yyyy hh:mm:ss»). once the data is in staging table, you may write appropriate SQL statement to insert into correct table.

See more:

I have Student Attendance Excel in Which I filling attendance detail of student at last of month I upload that excel sheet in database.When uploading excel sheet I getting this error

Error Uploading all Records.Object reference not set to an instance of an object

Comments

The issue in the title does not match the error message.
Please improve your question and give relevant details, including the code block that is throwing the exception. Do not post code in comments; please press the «Improve question» button instead.


1 solution

Solution 1

Function SQLDate(d)
SQLDate = WorksheetFunction.Text(d, «yyyy-mm-dd hh:MM:ss»)
End Function

or else

if staging table is an option, you could convert Excel date to string using
TEXT(d,»dd mmmm yyyy hh:mm:ss»). once the data is in staging table, you may write appropriate SQL statement to insert into correct table.

Понравилась статья? Поделить с друзьями:
  • Excel формат даты в русскую
  • Excel формат даты в родительном падеже
  • Excel формат даты в кварталах
  • Excel формат даты в днях
  • Excel формат даты без точек