Click here to Skip to main content
15,888,610 members
Home / Discussions / C#
   

C#

 
QuestionHow to count total properties in a class. Pin
sun255-Jul-06 6:58
sun255-Jul-06 6:58 
AnswerRe: How to count total properties in a class. Pin
Josh Smith5-Jul-06 7:14
Josh Smith5-Jul-06 7:14 
GeneralRe: How to count total properties in a class. Pin
sun255-Jul-06 21:22
sun255-Jul-06 21:22 
QuestionVBA and .NET Pin
rattack5-Jul-06 5:59
rattack5-Jul-06 5:59 
AnswerRe: VBA and .NET Pin
ToddHileHoffer5-Jul-06 6:01
ToddHileHoffer5-Jul-06 6:01 
GeneralRe: VBA and .NET Pin
rattack5-Jul-06 23:12
rattack5-Jul-06 23:12 
QuestionI wanna to format any date like SQL Date without changing Regional setting? Pin
3DoorsDown5-Jul-06 4:35
3DoorsDown5-Jul-06 4:35 
AnswerRe: I wanna to format any date like SQL Date without changing Regional setting? Pin
ToddHileHoffer5-Jul-06 5:17
ToddHileHoffer5-Jul-06 5:17 
The following function will format a datetime like the old vb dateformat and return a varchar. I use this all the time to format dates in my applications.



/****** Object: UserDefinedFunction [dbo].[udf_FormatDate] Script Date: 07/05/2006 11:11:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create FUNCTION [dbo].[udf_FormatDate] (@date datetime, @format varchar(50))
RETURNS VARCHAR(50) AS
BEGIN
-------------------------------------------------------------------------------------
--
-- Name: FormatDate
--
-- Purpose: Mimics the VB Format routine for dates
--
-- Parameters:
-- @date - Date, Date to be formatted
-- @format - String, Template to format the date to
--
-- Returns: String, Date formatted to user requested template
--
-- Notes:
-- 1. Time information is not accounted for in this routine
--
-- 2. @format accepts the following values for each section of the date.
-- Day
-- dddd - Full Day Name
-- ddd - Abbreviated Day Name
-- dd - Zero Padded Day Number
-- d - Day Number
--
-- Month
-- mmmm - Full Month Name
-- mmm - Abbreviated Month Name
-- mm - Zero Padded Month Number
-- m - Month Number
--
-- Year
-- yyyy - Full 4 digit year
-- yy - 2 digit year
--
-- 3. Any unexpected characters will be returned in the string
--
-- 4. Assumes database was set up with case-insensitive collation
--
-- Example Usage:
-- All examples use the following date 2003-07-13 00:00:00
--
-- 'dddd, mmmm dd, yyyy' --> Sunday, July 13, 2003
-- 'mmddyyyy' --> 07132003
-- 'm-d-yy' --> 7-13-03
-- 'mm/dd/yyyy' --> 07/13/2003
--
-------------------------------------------------------------------------------------
DECLARE @pos AS INTEGER
DECLARE @char AS VARCHAR(1)
--
-- Replace Year
--
SET @pos = CHARINDEX('yyyy', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 4, DATENAME(yyyy, @date))
--PRINT @format
SET @pos = CHARINDEX('yyyy', @format)
END

SET @pos = CHARINDEX('yy', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 2, RIGHT(DATENAME(yyyy, @date) ,2))
--PRINT @format
SET @pos = CHARINDEX('yy', @format)
END
--
-- Replace Month
--
SET @pos = CHARINDEX('mmmm', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 4, DATENAME(month, @date))
--PRINT @format
SET @pos = CHARINDEX('mmmm', @format)
END

SET @pos = CHARINDEX('mmm', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 3, LEFT(DATENAME(month, @date), 3))
--PRINT @format
SET @pos = CHARINDEX('mmm', @format)
END
SET @pos = CHARINDEX('mm', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 2, RIGHT(('0' + CAST(DATEPART(month, @date) AS VARCHAR(2))), 2))
--PRINT @format
SET @pos = CHARINDEX('mm', @format)
END

SET @pos = CHARINDEX('m', @format)
WHILE @pos > 0
BEGIN
-- account for MArch and deceMBer
SET @char = SUBSTRING(@format, @pos + 1, 1)
IF (@char <> 'a') AND (@char <> 'b')
BEGIN
SET @format = STUFF(@format, @pos, 1, CAST(DATEPART(month, @date) AS VARCHAR(2)))
--PRINT @format
SET @pos = CHARINDEX('m', @format)
END
ELSE
BEGIN
SET @pos = CHARINDEX('m', @format, @pos + 1)
END
END
--
-- Replace Day
--
SET @pos = CHARINDEX('dddd', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 4, DATENAME(weekday, @date))
--PRINT @format
SET @pos = CHARINDEX('dddd', @format)
END

SET @pos = CHARINDEX('ddd', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 3, LEFT(DATENAME(weekday, @date), 3))
--PRINT @format
SET @pos = CHARINDEX('ddd', @format)
END
SET @pos = CHARINDEX('dd', @format)
WHILE @pos > 0
BEGIN
SET @format = STUFF(@format, @pos, 2, RIGHT(('0' + DATENAME(day, @date)), 2))
--PRINT @format
SET @pos = CHARINDEX('dd', @format)
END
SET @pos = CHARINDEX('d', @format)
WHILE @pos > 0
BEGIN
-- account for DEcember, sunDAy --> saturDAy, weDNesday
SET @char = SUBSTRING(@format, @pos + 1, 1)
IF (@char <> 'e') AND (@char <> 'a') AND (@char <> 'n')
BEGIN
SET @format = STUFF(@format, @pos, 1, CAST(DATEPART(day, @date) AS VARCHAR(2)))
--PRINT @format


SET @pos = CHARINDEX('d', @format)
END
ELSE
BEGIN
SET @pos = CHARINDEX('d', @format, @pos + 1)
END
END
IF @format = '//' BEGIN
SET @format = ''
END
RETURN @format
END

how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
AnswerRe: I wanna to format any date like SQL Date without changing Regional setting? Pin
Colin Angus Mackay5-Jul-06 5:17
Colin Angus Mackay5-Jul-06 5:17 
AnswerRe: I wanna to format any date like SQL Date without changing Regional setting? Pin
Martin#5-Jul-06 5:17
Martin#5-Jul-06 5:17 
QuestionShadowcopy Pin
kokilambal.p5-Jul-06 4:00
kokilambal.p5-Jul-06 4:00 
AnswerRe: Shadowcopy Pin
Josh Smith5-Jul-06 7:15
Josh Smith5-Jul-06 7:15 
GeneralRe: Shadowcopy Pin
Not Active5-Jul-06 7:49
mentorNot Active5-Jul-06 7:49 
GeneralRe: Shadowcopy Pin
Josh Smith5-Jul-06 10:21
Josh Smith5-Jul-06 10:21 
GeneralRe: Shadowcopy Pin
kokilambal.p5-Jul-06 21:21
kokilambal.p5-Jul-06 21:21 
QuestionC# Cross-Class function calls Pin
czell5-Jul-06 3:57
czell5-Jul-06 3:57 
AnswerRe: C# Cross-Class function calls Pin
BoneSoft5-Jul-06 4:14
BoneSoft5-Jul-06 4:14 
AnswerRe: C# Cross-Class function calls Pin
Jun Du5-Jul-06 4:31
Jun Du5-Jul-06 4:31 
GeneralRe: C# Cross-Class function calls Pin
led mike5-Jul-06 6:33
led mike5-Jul-06 6:33 
QuestionHow to find 24Hrs Back Time Pin
VenkataRamana.Gali5-Jul-06 3:34
VenkataRamana.Gali5-Jul-06 3:34 
AnswerRe: How to find 24Hrs Back Time Pin
stancrm5-Jul-06 3:39
stancrm5-Jul-06 3:39 
AnswerRe: How to find 24Hrs Back Time Pin
MatthewAnderson5-Jul-06 3:40
MatthewAnderson5-Jul-06 3:40 
GeneralRe: How to find 24Hrs Back Time Pin
Guffa5-Jul-06 4:03
Guffa5-Jul-06 4:03 
GeneralRe: How to find 24Hrs Back Time Pin
Guffa5-Jul-06 4:07
Guffa5-Jul-06 4:07 
QuestionProblem with Diagnostics.Process Pin
suguimoto5-Jul-06 3:28
suguimoto5-Jul-06 3:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.