I dont want to use Convert(Char(9),date,106) function to show date in dd/MM/yyyy format. It changes the datatype of my column to char & I cant perform other date operations on it without changing it back to datetime.
Is there any T-sql way of doing it?
6 24140
Why would you care what format date has when you do data manipulation.
Use convert function only in select close when you try to display this date to a user. -
SELECT Convert(Char(9),date,106) Date
-
FROM some_table
-
WHERE date > dateadd(d, -10, getdate())
-
ORDER BY date
Good Luck.
You are trying to get the datetime formatted in a non-standard format but still be able to use it in the date?
I would suggest creating a second column with the altered format, use that for viewing, and use the original for altering, updating, and calculating.
A couple of other options:
A bit verbose, but you can do this:
select
dtForm = cast(day(dateField) as varchar) + '/' + cast(month(dateField) as varchar) + '/' + cast(year(dateField) as varchar)
obviously, "dateField" is the name of whatever date field you're pulling from the database. If you still wanted that as a date, you could always recast that back to datetime with the cast function, just like I was doing with the varchar.
If you are doing it in a datagrid, just change the defaultcellstyle of the date column. "d" is the short date format mm/dd/yyyy
Me.dataGridView1.Columns("NameOfDateColumn").Defau ltCellStyle.Format = "d"
The cell will still hold the datetime value from the database, but will only show the converted date to the user.
Why would you care what format date has when you do data manipulation.
Use convert function only in select close when you try to display this date to a user. -
SELECT Convert(Char(9),date,106) Date
-
FROM some_table
-
WHERE date > dateadd(d, -10, getdate())
-
ORDER BY date
Good Luck.
Excuse me, can you tell me why char(9) is used for an argument for Convert()
Thanks
Dave
this link has the details explanation:
http://www.dreamincode.net/forums/showtopic42872.htm
manpakhong@hotmail.com
Excuse me, can you tell me why char(9) is used for an argument for Convert()
Thanks
Dave
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Westcoast Sheri |
last post by:
When I used the "date("nj")" function to generate an invoice, about 1
out of 500 times, nothing comes up
<?php
$invoicedate = date("nj");
?>
<html><head></head><body>
Invoice date:
<?php...
|
by: Funnyweb |
last post by:
I have just notices that the date() function is not returning the correct
date/time on my "server".
I am running apache2 on my winxp pro laptop.
My system clock is set to the correct date,...
|
by: ethoemmes |
last post by:
Hi
I am trying to use the below functions to return the month for a given
date. I want the month displayed as Jan for 01 so I wrapped the Month
function in the Format function.
Month:...
|
by: Patrick McGuire |
last post by:
I need to get the current date in vb .NET. In vba I
always used the Date() function, and the help in .NET
indicates that this function still exists, but I can't
seem to find it. The Now()...
|
by: KJ |
last post by:
Hello,
Why does this not work?
txtMoney.Text.Format("#,##0.00")
If I type 100 in txtMoney, it returns #,##0.00
I have never gotten the format function to work in .NET.
|
by: Al Reid |
last post by:
First, I'm using vb2005. I have a string that is read from a barcode reader into a TextBox. The string is 6 characters long and
represents a date (mmddyy). I want to display it to the user in a...
|
by: Steve Long |
last post by:
Hello,
I'm encountering a bug, or user error, with the Format function and I'm
wondering if someone can either straighten me out or confirm the bug.
I'm passing in a Date to the Format function...
|
by: fniles |
last post by:
How do you do Format(Date, "mmddyy") in VB.NET ?
Thank you
|
by: walterbyrd |
last post by:
My MySQL table has a field that is set as type "date." I need to get
today's date, and insert it into that field. The default for that MySQL
field is 2006-00-00.
I know about the date()...
|
by: murch.alexander |
last post by:
I made a simple public function to set and return a date value (see
below). I have a number of queries that call up the function to get
the "As Of Date," which is typically set to today's date....
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
|
by: F22F35 |
last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...
| |