C# .NET - function to convert date format

Asked By rajani maski
09-Feb-10 12:55 AM
hi...
please can anyone let me know how the iso date formats to be converted into regular readable format?
eg: 1985102,1985W155 to be converted into 1985 april 12th friday.Code in c# or any easiest logic to get this.. hi...
please can anyone let me know how the iso date formats to be converted into regular readable format?
eg: 1985102,1985W155 to be converted into 1985 april 12th friday.Code in c# or any easiest logic to get this..
  Santhosh N replied to rajani maski
09-Feb-10 01:06 AM
You can format the date in c# using .ToString("format of Date") on datetime variable

for Ex:
DateTime dt = new DateTime(2009, 10, 10);
dt.ToString("D", CultureInfo.CreateSpecificCulture("en-US"))

this will display as DayOf the Week, Month 10, 2008 
check http://msdn.microsoft.com/en-us/library/az4se3k1.aspx for more info and other formats                      
  Sakshi a replied to rajani maski
09-Feb-10 01:18 AM
see http://msdn.microsoft.com/en-us/library/az4se3k1.aspx. It has all format conversions like ISO,etc.
  Sakshi a replied to rajani maski
09-Feb-10 01:18 AM
see http://msdn.microsoft.com/en-us/library/az4se3k1.aspx. It has all format conversions like ISO,etc.
  rajani maski replied to Santhosh N
09-Feb-10 01:22 AM
hi..thanks lot for reply..:)
 
I needed to know if i give input as say 1985W155 that is year 1985 week15th 5th day..or
1985102..that is 102th day of year 1985...I want display as "april 12th 1985 friday"

What code or function shall i write to get that output for said input that is in isodate format?
Awaiting your reply.
rajani@pointcross.com
  rajani maski replied to Sakshi a
09-Feb-10 01:28 AM
hi sakshi...Thankyou for link...but that is not solving my problem..i need to convert date formats not the representation formats..Eg: if i give input as 102th day of 1985...i need output as april 12th 1985,friday"  like wise..for 1985W155..its week15th 5thday of 1985...which must give op as "april 12th 1985,friday"


Awaiting reply
rajani@pointcross.com
  Anoop S replied to rajani maski
09-Feb-10 02:49 AM
assume input as string and check the length of string and  if its 7 the the write the code for that-eg 1985102,- add 102 ads using datetime.adddays(102) and string length 8(1985W155) the extract the string (0-3)-1985, st(5-6) -15, st7-5, then multiply 17* 7 + add days the use above method to add days,  there will be some easier methods other than this, lets check method in DateTime.UtcNow. function 
  Anoop S replied to Anoop S
09-Feb-10 02:55 AM
method in DateTime.UtcNow. function => DateTime.UtcNow (no option for edit )
  rajani maski replied to Anoop S
09-Feb-10 03:45 AM
hello anoop..Thanks for the reply..Yeah i have applied the same methd that u said...but its being lengtheir..And there are n number of iso formats like that..To convert them into regular readable format is being hectic task..neways,if u find any simpler way..pls lemme know...

awaiting answer..
Regards,
Rajani Maski
  Sakshi a replied to rajani maski
09-Feb-10 03:53 AM
for that u need to write custom code.
  Santhosh N replied to rajani maski
09-Feb-10 04:17 AM
you can check the custom formats here and if your input dates matches any of the formats and culture specific formats you could convert them appropriately..
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
other than that, I am afraid you need to corret the source dates or apply your custom logic...
  rajani maski replied to Santhosh N
09-Feb-10 04:30 AM
ok...how to write custom code? pl jus gimme lil xample..ill continue it than...
  Santhosh N replied to rajani maski
09-Feb-10 09:42 AM
plz read in detail the link, it has the info...

and let me know for further info
Create New Account
help
set day according to month hi, people. I've got a date that needs to be set to a specific day for each month. But if the 0))) day = 29; return day; } [ / code] [code] int day = CheckDays(start.Year, start.Month, validDay); DateTime validation = new DateTime(start.Year, start.Month, day); / / display result foreach (DateTime date in GetDates(validation, end)) { dt.Rows.Add((date.ToShortDateString())); } [ / code> this code outputs: Valuation Date 30 / 06 / 2009 30 / 07 / 2009 30 / 08 / 2009 30 / 09 / 2009 30 / 10 / 2009 you try to assign invalid day (for e.g. day 31 to April 2010) on datetime variable, you will get error something like: ArgumentOutOfRangeException (Year, Month, and Day parameters describe an
query into sql server query Sum(IIf(Month([UseDate]) & " / " & Year([UseDate]) = (Month(DateAdd("m", -11, Date())) & " / " & Year(DateAdd("m", -11, Date()))), 1, 0)) AS Mo1Sum above is my access query syntax and i want to convert value. what about second value? Sum( IIf(Month([UseDate]) & " / " & Year([UseDate]) = (Month(DateAdd("m", -11, Date())) & " / " & Year(DateAdd("m", -11, Date()))), 1, 0) / / First value , "Missing Second Value" ) AS Mo1Sum / / I hope You Can Understand Your whole query. . . . hey below is my whole query: SELECT qryCallDates.ReferredOffice, Month(DateAdd("m", -11, Date())) & " / " & Year(DateAdd("m", -11, Date())) AS Mo1Name, Sum(IIf(Month([UseDate]) & " / " & Year([UseDate]) = (Month(DateAdd("m", -11, Date())) & " / " & Year(DateAdd("m", -11, Date()))), 1, 0)) AS Mo1Sum, Sum(IIf(Month([UseDate]) & " / " & Year([UseDate]) = (Month(DateAdd("m", -10, Date
el.offsetTop; } return ot; } function AnchorPosition_getWindowOffsetTop (el) { return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop; } / * SOURCE FILE: date.js * / / / HISTORY / / - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - / / May 17, 2003: Fixed bug in parseDate() for dates <1970 / / March 11, 2003 up / / perfectly with SimpleDateFormat formats, but / / backwards-compatability was required. / / - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - / / These functions use the same 'format' strings as the / / java.text.SimpleDateFormat class, with minor exceptions. / / The format string consists of the following abbreviations: / / / / Field | Full Form | Short Form / / - -- -- -- -- -- --+- -- -- -- -- -- -- -- -- -- -+- -- -- -- -- -- -- -- -- -- -- -- / / Year | yyyy (4 digits LZ(x) { return (x<0 | | x> 9? "" : "0" )+x} / / - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - / / isDate ( date_string, format_string ) / / Returns true if date string matches format of format string and / / is a valid date. Else returns false. / / It is recommended that you trim whitespace around the value before / / passing it to this function, as whitespace is NOT ignored! / / - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - function isDate(val, format) { var date = getDateFromFormat(val, format); if (date = = 0) { return false ; } return true ; } / / - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- / / compareDates(date1, date1format
minute age, 1 day ago or 1 month ago here i m updating last login date and time in my table when any user login. now i want to calculate last let you know incase if i find anything simple! To get the difference between 2 datetime values in terms of minutes, hours, days or months, you can use the DATEDIFF date function. The DATEDIFF function has the following syntax: DATEDIFF(datepart, startdate, enddate) So to get helper.com / faq / dates-p02.aspx hi, in sql server we have the default inbuild date functions. . . . from that we can findout the datediff, times. . . . DATEDIFF(datepart, startdate, enddate) here some more details: Custom DateTime Format Strings A custom DateTime format string consists of one or more custom DateTime format specifiers, and that format string defines