Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #1730 > unrolled thread

How to remove the time part from a field in sql server database when I make a select

Started by"Tony Johansson" <johansson.andersson@telia.com>
First post2014-03-15 14:37 +0100
Last post2014-03-15 17:31 +0100
Articles 3 — 2 participants

Back to article view | Back to comp.databases.ms-sqlserver


Contents

  How to  remove the time part from a field in sql server database when I make a select "Tony Johansson" <johansson.andersson@telia.com> - 2014-03-15 14:37 +0100
    Re: How to  remove the time part from a field in sql server database when I make a select "Tony Johansson" <johansson.andersson@telia.com> - 2014-03-15 16:58 +0100
    Re: How to remove the time part from a field in sql server database when I make a select Erland Sommarskog <esquel@sommarskog.se> - 2014-03-15 17:31 +0100

#1730 — How to remove the time part from a field in sql server database when I make a select

From"Tony Johansson" <johansson.andersson@telia.com>
Date2014-03-15 14:37 +0100
SubjectHow to remove the time part from a field in sql server database when I make a select
Message-ID<lg1l34$knv$1@dont-email.me>
In this method GetBokningar I fetch all rows and return a DataSet but I hope 
I can remove the time part in some way.
Now I get for example format 2013-03-12 00:00:00 for columns BokningFromDate 
and BokningToDate because these are DateTime column in the database.
I could use  a DataReader and convert to string but I hope I can fix it 
within sql in some way.

public DataSet GetBokningar()
  {
   Command.Parameters.Clear();
   Connection.Open();

   Command.CommandText = "SELECT BokningFromDate, BokningToDate, Name, 
Address, Phone, ProductID, EnhetsPris " +
          "FROM Bokningar " +
          "INNER JOIN Customers " +
          "ON Bokningar.CustomerID = Customers.CustomerID " +
          "INNER JOIN BokningDetails " +
          "ON Bokningar.BokningarID = BokningDetails.BokningarID " +
          "ORDER BY Name asc";

   dataAdapter = new SqlDataAdapter(Command);
   DataSet ds = new DataSet();
   dataAdapter.Fill(ds, "Products");
   return ds;
  }

//Tony 

[toc] | [next] | [standalone]


#1731

From"Tony Johansson" <johansson.andersson@telia.com>
Date2014-03-15 16:58 +0100
Message-ID<lg1tba$hr7$1@dont-email.me>
In reply to#1730
Solved I used this
DataFormatString="{0:yyyy-MM-dd}"

//Tony
"Tony Johansson" <johansson.andersson@telia.com> skrev i meddelandet 
news:lg1l34$knv$1@dont-email.me...
> In this method GetBokningar I fetch all rows and return a DataSet but I 
> hope I can remove the time part in some way.
> Now I get for example format 2013-03-12 00:00:00 for columns 
> BokningFromDate and BokningToDate because these are DateTime column in the 
> database.
> I could use  a DataReader and convert to string but I hope I can fix it 
> within sql in some way.
>
> public DataSet GetBokningar()
>  {
>   Command.Parameters.Clear();
>   Connection.Open();
>
>   Command.CommandText = "SELECT BokningFromDate, BokningToDate, Name, 
> Address, Phone, ProductID, EnhetsPris " +
>          "FROM Bokningar " +
>          "INNER JOIN Customers " +
>          "ON Bokningar.CustomerID = Customers.CustomerID " +
>          "INNER JOIN BokningDetails " +
>          "ON Bokningar.BokningarID = BokningDetails.BokningarID " +
>          "ORDER BY Name asc";
>
>   dataAdapter = new SqlDataAdapter(Command);
>   DataSet ds = new DataSet();
>   dataAdapter.Fill(ds, "Products");
>   return ds;
>  }
>
> //Tony 

[toc] | [prev] | [next] | [standalone]


#1734 — Re: How to remove the time part from a field in sql server database when I make a select

FromErland Sommarskog <esquel@sommarskog.se>
Date2014-03-15 17:31 +0100
SubjectRe: How to remove the time part from a field in sql server database when I make a select
Message-ID<XnsA2F1B253CFBF1Yazorman@127.0.0.1>
In reply to#1730
Tony Johansson (johansson.andersson@telia.com) writes:
> In this method GetBokningar I fetch all rows and return a DataSet but I
> hope I can remove the time part in some way. Now I get for example
> format 2013-03-12 00:00:00 for columns BokningFromDate and BokningToDate
> because these are DateTime column in the database. I could use  a
> DataReader and convert to string but I hope I can fix it within sql in
> some way. 

Presentation issues are best done in the UI, but you could use the data
type date throughout in the database. Or you could do

convert(date, BookingFromDate)


-- 
Erland Sommarskog, Stockholm, esquel@sommarskog.se

[toc] | [prev] | [standalone]


Back to top | Article view | comp.databases.ms-sqlserver


csiph-web