473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

date format (mm/dd/yyyy)

I am using system.datetime.today to get today's date. I want to send this value to a date field in sql server in the mm/dd/yyyy format, but it is sending the date in mm/d/yyyy format. It's not sending trailing zero for a single digit day. For example; if today's date is 12/08/2009, it is giving me 12/8/2009 instead of 12/08/2009. Please advise how can I accomplish this.

Thanks
Dec 14 '09 #1

✓ answered by tlhintoq

It would help if we saw the code you are using to format the date to your needs.
You should be able to use the .ToString() method to format as needed.

Expand|Select|Wrap|Line Numbers
  1. myDateTimeObject.ToString("MM/dd/yyyy")
;

5 3194
tlhintoq
3,525 Expert 2GB
It would help if we saw the code you are using to format the date to your needs.
You should be able to use the .ToString() method to format as needed.

Expand|Select|Wrap|Line Numbers
  1. myDateTimeObject.ToString("MM/dd/yyyy")
;
Dec 14 '09 #2
I am actually storing this value in date type variable, so can't use .tosring("mm/dd/yyyy"). I am planning to store this value in string variable now.
Thanks
Dec 14 '09 #3
Hello tlhintoq
Actually, when I send this value to sql serverdatabase, then it gets converted to 12/8/2009 from 12/08/2009. Im using the following code:
cmd.Parameters.Add("@MailOptOutDate", SqlDbType.VarChar).Value = ((System.DateTime.Today).AddDays(-10)).ToString("MM/dd/yyyy");
Thanks
Dec 14 '09 #4
Plater
7,872 Expert 4TB
Hmmm a DateTime(or date) field has NO specific format. How you display it is up to you.
Dec 15 '09 #5
I have figured it out myself. I was having trouble when I was trying to retrieve the date from the database & display it in mmddyyyy format in a fixed length file as we can not use format on date variables. I used the cast & was able to display it in correct format.
Dec 15 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Alistair | last post by:
it's the idiot with his query strings again...."yippeee" I hear aaron shout this time the problem is with a date format query I have a query string thus strSQL = "SELECT * FROM users where...
2
by: Ian | last post by:
I have a problem I hope someone can point out where I am going wrong. I need to store a date/time in a cookie ( ie the date a visitor last visited ) However the date format changes to US, despite...
1
by: jt | last post by:
I posted this yesterday, but I am not seeing this out yet: I am having problems with updating a date field in a certain format. The data is stored in an Oracle database. The date is...
6
by: Dario Di Bella | last post by:
Hi all, we have the following urgent issue affecting our development team. Initially we had one particular workstation that failed executing queries on a DB2 database, raising an invalid date...
5
by: Macca | last post by:
Hi, I have a table which has a date/time field. I am storing them as follows :- 01/01/2005 11:25 01/01/2005 19:44 02/01/2005 05:04
7
by: Richiep | last post by:
I am trying to get a UK format date of dd/mm/yyyy. Why does the following subroutine not return a valid date in a web form? The date returned is #12:00:00 AM# but the date I entered into the...
4
by: saintor1 | last post by:
Access 97 - I want the date format YYYY-M M-DD to show everywhere. My problem is that I deal with French and English versions. And don't want to play with Windows Regional Settings. In the...
1
by: saddist | last post by:
Hello, In access 2003 I have date format yyyy/mm/dd, but I want it to be dd/mm/yyyy. I tried to enter dd"/"mm"/"yyyy and dd/mm/yyyy in format property, but it changes automaticly to dd/mm"/yyyy"....
10
by: ARC | last post by:
Hello all, General question for back-end database that has numerous date fields where the database will be used in regions that put the month first, and regions that do not. Should I save a...
3
by: Tony WONG | last post by:
The date format (control panel) of testing (VS2005) and production platform are yyyy/mm/dd. i run preview from testing (VS2005). The date format is yyyy/mm/dd however, when i put the code to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.