Avatar billede kinnerup Nybegynder
27. april 1999 - 00:00 Der er 1 kommentar og
1 løsning

indtastningsformat for SMALLDATETIME

I hvilket format skal indtaste i dato og tid i et felt som er defineret som SMALLDATETIME?

Jeg bruger PHP til at udføre SQL kommandoer via ODBC.

-- Mikkel
Avatar billede ruprect Nybegynder
27. april 1999 - 23:52 #1
Datetime datatypes:
Datatype
Avatar billede ruprect Nybegynder
27. april 1999 - 23:57 #2
Whoops, der var jeg vist lige lidt for hurtig med min <tab> <space> kombination :)

Så jeg prøver lige igen..

Jeg fandt dette på http://www.mcp.com/ (til alle jer der ikke skriver http:// foran web adresser: Prøv venligst at huske det, man slipper for at cut'n'paste)

---------------

Date and time data can be stored in either a datetime or a smalldatetime datatype.

Date and time data can take several different formats. You can specify the month using the full name or an abbreviation. The case is ignored and commas are optional.

Here are some examples using the alpha formats for April 15, 1996:

Apr 15 1996
Apr 15 96
Apr 96 15
15 Apr 96
1996 April 115
1996 15 April



--------------------------------------------------------------------------------
NOTE: If only the last two digits of the year are given, SQL Server will interpret values of less than 50 as 20yy, while numbers greater-than or equal-to 50 will be interpreted as 19yy. For example, April 15 03 would be interpreted as April 15, 2003.

This is different from the Microsoft Visual Basic 5.0 and the Office 95/97 products, which interpret values less than 30 as 20yy and values greater-than or equal-to 30 as 19yy.
--------------------------------------------------------------------------------

You can also specify the ordinal value for the month. The ordinal value of an item is the positional value within a list of items. In the previous examples, April is the fourth month of the year, so you can use the number 4 as its designation.

Here are some examples using the ordinal value for April 15, 1996:

4/15/96 (mdy)
4-15-96 (mdy)
4.15.96 (mdy)
4/96/15 (myd)
15/96/04 (dym)
96/15/04 (ymd)

There are also several different time formats you can use. Here are some examples:

16:30 (4 hrs, 30 mins)
16:30:20:999 (4 hrs, 30 mins, 22 seconds, 999 milliseconds)
4:30PM

Dates stored in the datetime datatype are stored to the millisecond. A total of eight bytes are used, four for the number of days since January 1, 1900 and four for the number of seconds past midnight. (Dates prior to this are stored as negative numbers, making the range of dates 1/1/1753 to 12/31/9999.) The accuracy of your dates is within 3.33 milliseconds.

With the smalldatetime datatype, a total of four bytes are used. Dates stored this way are accurate to the minute. Internally, one smallint (two bytes) is used for the number of days after January 1, 1900, and the other smallint is used for the number of seconds past midnight. The range for a smalldatetime is 1/1/1900 to 6/6/2079.

Table 5.6 delineates the datetime datatypes.

Table 5.6. Datetime datatypes.
Datatype______Storage___Range
datetime______8_________1/1/1753-12/31/9999
smalldatetime_4_________1/1/1900-6/6/2079

--------------------------------------------------------------------------------
TIP: Use smalldatetime for current dates in databases, especially those that are transitory in nature. These would be dates that you are not going to be using for more than a few years.

Do not use datetime to store partial dates, such as only the month, day, or year. If the only data needed is the year, a smallint or tinyint would be much more efficient. If you do not do this, you will have to parse the date yourself every time you want to insert, update, or otherwise work with the information.

Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Computerworld tilbyder specialiserede kurser i database-management

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester