Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET4.0
hi
all
 
i need to get date in yyyy-mm-dd format in data type datatime.
 

thanks in advance
Posted 29-Mar-12 21:37pm
Ragi Gopi1.3K
Comments
Sebastian T Xavier at 30-Mar-12 2:38am
   
Do you want it in c# or SQL?
Ragi Gopi at 30-Mar-12 2:56am
   
Dear frnds iam talking about assigning current date to datetime variable in yyyy-MM-dd format in asp.net not to string datatype.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Ragi Gopi at 30-Mar-12 2:55am
   
Dear frnds iam talking about assigning current date to datetime variable in yyyy-MM-dd format in asp.net not to string datatype.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

you can try these methods
String.Format in c#
Convert() in sql server
try DateTime.ParseExact method
DateTime dt = DateTime.ParseExact(DateTime.Now.ToString(), "yyyy-MM-dd", CultureInfo.InvariantCulture);
  Permalink  
v2
Comments
Ragi Gopi at 30-Mar-12 2:56am
   
Dear frnds iam talking about assigning current date to datetime variable in yyyy-MM-dd format in asp.net not to string datatype.
Uma Shankar Patel at 30-Mar-12 5:28am
   
try updated answer
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

you can find some options here .....
 
C#[^]
 
SQL[^]
 
Regards
  Permalink  
Comments
Ragi Gopi at 30-Mar-12 2:56am
   
Dear frnds iam talking about assigning current date to datetime variable in yyyy-MM-dd format in asp.net not to string datatype.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Few sample code:
 
// create date time 2012-03-29 16:05:07.123
DateTime dt = new DateTime(2012, 3, 29, 16, 5, 7, 123);
 
String.Format("{0:y yy yyy yyyy}", dt);  // "8 08 008 2008"   year
String.Format("{0:M MM MMM MMMM}", dt);  // "3 03 Mar March"  month
String.Format("{0:d dd ddd dddd}", dt);  // "9 09 Sun Sunday" day
String.Format("{0:h hh H HH}",     dt);  // "4 04 16 16"      hour 12/24
String.Format("{0:m mm}",          dt);  // "5 05"            minute
String.Format("{0:s ss}",          dt);  // "7 07"            second
String.Format("{0:f ff fff ffff}", dt);  // "1 12 123 1230"   sec.fraction
String.Format("{0:F FF FFF FFFF}", dt);  // "1 12 123 123"    without zeroes
String.Format("{0:t tt}",          dt);  // "P PM"            A.M. or P.M.
String.Format("{0:z zz zzz}",      dt);  // "-6 -06 -06:00"   time zone

// month/day numbers without/with leading zeroes
String.Format("{0:M/d/yyyy}", dt);            // "3/9/2008"
String.Format("{0:MM/dd/yyyy}", dt);          // "03/09/2008"

// day/month names
String.Format("{0:ddd, MMM d, yyyy}", dt);    // "Sun, Mar 9, 2008"
String.Format("{0:dddd, MMMM d, yyyy}", dt);  // "Sunday, March 9, 2008"

// two/four digit year
String.Format("{0:MM/dd/yy}", dt);            // "03/09/08"
String.Format("{0:MM/dd/yyyy}", dt);          // "03/09/2008"
  Permalink  
v2
Comments
Ragi Gopi at 30-Mar-12 2:56am
   
Dear frnds iam talking about assigning current date to datetime variable in yyyy-MM-dd format in asp.net not to string datatype.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

txtDate.Text = DateTime.Now.ToUniversalTime().AddMinutes(DateTime.Now.Subtract(DateTime.Now.ToUniversalTime()).TotalMinutes).ToString("dd/MM/yyyy");
  Permalink  
Comments
Ragi Gopi at 30-Mar-12 2:56am
   
Dear frnds iam talking about assigning current date to datetime variable in yyyy-MM-dd format in asp.net not to string datatype.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

if use datetimepicker then
set

datetimepicker.CustomFormat="yyyy/MM/dd"
datetimepicker.Format=system.windows.forms.datetimepickerformat.custom
 
hope this help
  Permalink  
Comments
Ragi Gopi at 30-Mar-12 2:56am
   
Dear frnds iam talking about assigning current date to datetime variable in yyyy-MM-dd format in asp.net not to string datatype.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 30 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100