.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Date Time Formatting to a specific dateformat

Posted By:      Posted Date: September 17, 2010    Points: 0   Category :ASP.Net
Hello All,I have been struggling with this for a long time. I have a form in which there is a textbox using an ajax calender extender. Now, the problem is that, I want to take the Date value which is string format and format it to a specific date format before inserting it into the database. The following is the core problem:Dim MDate as string=txtMeetingDate.Textdim d as new Datetime' I want to convert the d to a datetime using the Mdate/// The problem is that I don't know what's the date format in the TextBox because users can use any time format they want, it is based on their windows settings!!!So, I am struggling to change my String (MDate) into a DateTime in the same format the user have and then convert it into my format:"dd/MM/yyyy" and after I have the date in the correct format, I want to change it back to string and save it in the database.I am doing this so that I have the same dateformat saved in my database.Any Ideas? ThanksAMB

View Complete Post

More Related Resource Links

Returning record from History Table as it would have existed at a specific date/time


I have a table that uses a trigger to save changes (old values) to a history table. This process is working fine, and I have reports that detail the history of a record for the end user. My problem is that the end user now wants a report that will retrieve how the record looked at a specific date/time.

Source Table:

Id	First	Last	Active	Date
1	John	Doe	1	10/25/2010
2	Jane	Smith	1	10/25/2010

History Table:

Id	SourceId	First		Last	Active	Date
1	1		Jonathon	NULL	NULL	5/1/2000
2	2		NULL		Gray	NULL	10/1/2000
3	2		NULL		Smith	NULL	6/15/2003
4	2		NULL		Doe	NULL	11/23/2008

If the user queries for SourceId 2 on 1/1/2009, they need to get:

Id	First	Last	Active
2	Jane	Smith	1

I've used COALESCE searching multiple fields, but I need to figure out how to

Date and Time String Formatting With C#.NET

System.DateTime newDate = System.DateTime.Now;
Console.WriteLine("date: {0}", newDate);// Current Date Time will be display

Dates and Times in C# .NET

Date and Time Functions in SQLSERVER

Date and time functions allow you to manipulate columns and variables with DATETIME and SMALLDATETIME data types.

1 DATEPART Function
2 DATENAME Function
3 DAY, MONTH, and YEAR Functions
5 DATEADD Functions
6 DATEDIFF Function
7 More SQL Server Functions

Data Types - Date and Time in SqlServer

Date and time values can be stored with either the DATETIME or SMALLDATETIME data type. The difference between the two is that SMALLDATETIME supports a smaller range of dates and does not give the same level of precision when accounting for time. The DATETIME data type can hold values from January 1st of 1753 to December 31st of 9999. The time is stored to the 1 three hundredths of a second and each value takes up 8 bytes of storage. The SMALLDATETIME data type can hold values between January 1st 1900 and June 6th of 2079. The time is tracked to the minute and each value takes up 4 bytes of storage. The majority of business applications can live happily with SMALLDATETIME, however, if you are in an environment where each second matters or you need to make estimates to the distant future (or past) then you have to resort to DATETIME. If you fail to specify the time when inserting a value into a DATETIME or SMALLDATETIME column, a default of midnight is used. If you fail to specify the date portion the default of January 1, 1900 is used.

Built-in Functions - Date and Time Functions

Date and time functions allow you to manipulate columns and variables with DATETIME and SMALLDATETIME data types.

Essential SQL Server Date, Time and DateTime Functions

The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any formatting considerations at all.

Date/Time Conversions Using SQL Server

There are many instances when dates and times don't show up at your doorstep in the format you'd like it to be, nor does the output of a query fit the needs of the people viewing it. One option is to format the data in the application itself. Another option is to use the built-in functions SQL Server provides to format the date string for you.

Date and Time Data Types and Functions

The following sections in this topic provide an overview of all Transact-SQL date and time data types and functions. For information and examples that are common to date and time data types and functions

date formatting


I have a 3 field table in sql server express and one of the columns is a date.

I'm trying to pull that in and publish to a gridview, but when I do it comes in with the date and minutes and seconds, etc.

How can I format that so that I only publish MM/DD/YYYY?

thanks in advance 

CLR Inside Out: Formatting and Parsing Time Intervals in the .NET Framework 4


Learn about enhanced TimeSpan formatting and parsing features coming in the .NET Framework 4, and some helpful tips for working with TimeSpan values.

Ron Petrusha

MSDN Magazine February 2010

Convert Update Date/Time to VB.NET



I was wondering if someone could convert this into VB.NET for me.  I'm not a PHP pro and not entirely sure what's happening here nor do I know how to get this to display the same way.

The new field is within a DetailsView, so you can give me example code as well, I'll greatly appreciate it.

Thanks.. -Jeff

PHP Code:

function updFormat($tStamp) {
	$tsTime = (strftime('%I', $tStamp) + 0) . strftime(':%M %p', $tStamp);
	// 86400 == # of seconds in a day
	$tsDays = floor($tStamp / 86400);
	$nowDays = floor(time() / 86400);
	if ($tsDays == $nowDays) $updTime = "Today at $tsTime";
	elseif ($tsDays == $nowDays - 1) $updTime = "Yesterday at $tsTime";
	else $updTime = strftime('%b ', $tStamp) . (strftime('%d', $tStamp) + 0) . strftime(', %Y' , $tStamp);

	return $updTime;
<asp:DetailsView ID="dtv_LastUpdated" runat="server" Width="100%" 
    AutoGenerateRows="False" DataSourceID="ods_MVPParcelUpdate" 
    CellPadding="1" CellSpacing="1" GridLines="None">
        <asp:BoundField DataField="Update_time" HeaderText="Parcel Data:" 

Execute a function for specific time (not at specific time)


I have a function that does large amount of processing.

I just want that if it executes in specific time (say 10 min) then it should return "execution successful".

But if now then i want to stop the execution of that function and return "unsuccessful" and rollback my transactions.

Returning and rollback is fine.

But i dont know how to stop the execution of a function at specific time.

I am using asp.net with C#.

Any ideas would be really appreciated.


How to insert the Current date and time in to SQL Table..

Hello Members,              I have create the table as per the following ..create table company(  empname varchar(30),  empid int,  joindate smalldatetime)I tried,insert into table values('Kumar',202, ??????)I want to insert Current date and time into table Company.....Please give me the solution...Thanks.. 

Formatting the date with the CalendarExtender

I must be missing something here.  I use the code below to display a DateTime value, and the time is always displaying, i.e. 7/11/2010 08:10:10. I just want the date.  The Format value doesn't seem to have any effect.    <asp:TemplateField HeaderText="Exp Date" HeaderStyle-Width="100px">   <ItemTemplate>   <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("expirationDate") %>'></asp:TextBox>   <cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1" Format="MM/dd/yy" />   </ItemTemplate>   </asp:TemplateField>

Template for Date Time? Is this possible?

Hello,On my model I have a property, Birthday, of type DateTime.I need to have three Drop Down Lists: - Day- Month (Localized to Current Culture)- Year (Last 80 years including current year)How can I create a Template to for these 3 DropDownLists and then use it on my form for Birthday property?Thank You,Miguel

how to find local time and date usin gmt time and ofset value

Hi All, i have to calculate local time and date in our data base i have gmt time range from 00:00 to 23:59 and offset is in same range but with + an - sign when + then we have to substract and when - then we have add and adjest the date with the given time for eg  gmt id 23:30 and ofset is +2:30 and date is '28-08-2010' then my local time is 23:30 -2:30  =21:00 and date will not change i want a cricteria like when offset get added then value should not be like 22:60 insted of this it is 23:00 and if it is exiding 24 then date should be increase and if time is - after gmt+ofset then date should be redused   Please give me a idea so i can solve it.  

Should time date stamp on .Asmx file change when project is rebuilt?

I have a web service project. The web service is named Recalc.asmx and it has a code behind file namedRecalc.asmx.vb Now if I make a change to my web service .vb code and then recompile the project, should my Recalc.asmx filebe updated as well? In windows explorer I see that the time date stamp of my Racalc.asmx.vb file changes to the date of the last change.But the time date stamp of the Recalc.asmx file does not change? Why is that? My original thinking was that I would simply need to copy the Recalc.asmx file to the test server. But the date stillshows it's original creation date of 7/1/2010 and not the date of the last rebuild as I was hoping it would do?
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend