Wednesday, March 21, 2012
getdate() format problem
I am just trying to do a simple time stamp. When I do the following SQL
command
SELECT getdate() my book and Microsoft say I should get the format like thi
s:
3/22/2002 6:08:08 AM
Instead when I run this I get the following format:
2006-04-07 18:37:19.823
How do I get it to return the first format?
Thanks,
MichaelGETDATE() returns a datetime datatype, which has no particular display
format, as it is binary in nature. Unless you explicitly convert the
datetime to a character string, SQL Server has nothing to do with how
the date and time are displayed to you. That is a function of the
front end application, such as Query Analyzer (SQL Server 2000) or
Management Studio (SQL Server 2005).
To see what alternatives you have if you convert datetime to a string
explicitly, see the style parameter of the CONVERT function in Books
on Line.
Roy Harvey
Beacon Falls, CT
On Fri, 7 Apr 2006 16:50:02 -0700, Michael
<Michael@.discussions.microsoft.com> wrote:
>Hello,
>I am just trying to do a simple time stamp. When I do the following SQL
>command
>SELECT getdate() my book and Microsoft say I should get the format like th
is:
> 3/22/2002 6:08:08 AM
>Instead when I run this I get the following format:
> 2006-04-07 18:37:19.823
>How do I get it to return the first format?
>Thanks,
>Michael|||Try this:
declare @.date datetime
set @.date = getdate()
select convert(varchar(20), @.date, 101)+ ' ' +convert(varchar(20), @.date, 10
8)
"Roy Harvey" wrote:
> GETDATE() returns a datetime datatype, which has no particular display
> format, as it is binary in nature. Unless you explicitly convert the
> datetime to a character string, SQL Server has nothing to do with how
> the date and time are displayed to you. That is a function of the
> front end application, such as Query Analyzer (SQL Server 2000) or
> Management Studio (SQL Server 2005).
> To see what alternatives you have if you convert datetime to a string
> explicitly, see the style parameter of the CONVERT function in Books
> on Line.
> Roy Harvey
> Beacon Falls, CT
> On Fri, 7 Apr 2006 16:50:02 -0700, Michael
> <Michael@.discussions.microsoft.com> wrote:
>
>|||http://www.aspfaq.com/2464
http://www.aspfaq.com/2460
"Michael" <Michael@.discussions.microsoft.com> wrote in message
news:8669696A-88B3-4F33-88E5-42997C68B387@.microsoft.com...
> Hello,
> I am just trying to do a simple time stamp. When I do the following SQL
> command
> SELECT getdate() my book and Microsoft say I should get the format like
> this:
> 3/22/2002 6:08:08 AM
> Instead when I run this I get the following format:
> 2006-04-07 18:37:19.823
> How do I get it to return the first format?
> Thanks,
> Michael
Getdate Problem
Hi ,
I have problem with Getdate()
i want to create Guest book with VWD 2005 and SQL 2005
I have same problem here forQ1,
http://forums.asp.net/thread/1513111.aspx
I put the Defualt value for the date : getdate()
and then I create insert page, but i got the error below
I tried to [Allow Null] for the data field in sql 2005, but when I add new entries, there is no date entered to the DB.
Can you Help.
thank you
------------
Cannot insert the value NULL into column 'guestdate', table 'tour2.dbo.gues'; column does not allow nulls. INSERT fails.
The statement has been terminated
Given that a record can be entered when allow nulls is set to true, I'm guessing that there is a problem with how getdate() is written in the default value. Try changing the default value to include outside parenthesis, like: (getdate())
Good luck!
|||Hey
What is the create statement for the table?
You could execute insert statement in Sql Server Management studio to see if it works.
Here is an Example:
create table test_default_value(column1datetime defaultgetdate(),column2varchar(32))insert into test_default_value (column2)values('test')sql