Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 9th, 2007, 11:35 PM
Authorized User
 
Join Date: Dec 2006
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deb1980
Default Format datetime

Hi,

I have been trying to format last login date and time, however encoutered with runtime errors.

The code I used is:

Hi <%Response.Write(CType(Session("fname"), String))%>, you last logged in on <%=(Session("lastlogin").ToString("F"))%>


-----------------------------

The error i got:


Server Error in '/Accounts' Application.
--------------------------------------------------------------------------------

Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:


Line 72: <form id="form1" runat="server">
Line 73: <div>
Line 74: Hi <%Response.Write(CType(Session("fname"), String))%>, you last logged in on <%=(Session("lastlogin").ToString("F"))%>
Line 75: </div>
Line 76: </form>


Thanks in advance



---
Best regards,

Debashis
__________________
---
Best regards,

Debashis
http://debashis80.spaces.live.com/
 
Old April 10th, 2007, 06:44 AM
Authorized User
 
Join Date: Jun 2006
Posts: 47
Thanks: 0
Thanked 2 Times in 2 Posts
Default

hi,

don understand ur problem fully but still....

u can do this with alternate way too.
create a table and then in column of table u wrte ur session variable with modifications in the format of ur session variable in .cs page.



 
Old April 10th, 2007, 06:48 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I am going to assume that this part of the code is throwing the error is:
<%=(Session("lastlogin").ToString("F"))%>

What is the value of lastLogin? I think the problem you are having is that the value contained within can not be formatted as a Long Date and Time.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old April 10th, 2007, 12:51 PM
Authorized User
 
Join Date: Dec 2006
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deb1980
Default

Hi,

The data for the last login field in MSSQL db is: 2007-04-10 21:57:27.920
I want to format that in to long date time format, the code in my above post is what i had used, also getting runtime error.

However if i simply write:
Hi <%Response.Write(CType(Session("fname"), String))%>, you last logged in on <%=(Session("lastlogin"))%>

It gives me an output:
Hi Debashis, you last logged in on 4/10/2007 9:51:07 AM

I simply want to format the date and time as log datetime format!

Thanks

---
Best regards,

Debashis
 
Old April 11th, 2007, 12:47 AM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try this code

Convert.ToDateTime(Session("fname")).Date.ToString ("F")

Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"
 
Old April 11th, 2007, 12:13 PM
Authorized User
 
Join Date: Dec 2006
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deb1980
Default

Hi zaghmout,

The date seems to be coming fine, however the time always shows 12.00 AM.

The code i am using is:

Hi <%Response.Write(CType(Session("fname"), String))%>, you last logged in on <%=Convert.ToDateTime(Session("lastlogin")).Date.T oString("F")%>



The output for the above is:

Hi Debashis, you last logged in on Wednesday, April 11, 2007 12:00:00 AM


The date & time should have been 2007-04-11 22:38:37.763



---
Best regards,

Debashis
 
Old April 17th, 2007, 12:32 AM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry my mistake, I thought you want the only the date, okey the try this

Convert.ToDateTime(Session("lastlogin"))..Now.ToSt ring("yyyy MMM dd HH:MM:ss")

this will work

Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"
 
Old April 17th, 2007, 12:35 AM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry I copied and extra code :)
Convert.ToDateTime(Session("lastlogin")).ToString( "yyyy MMM dd HH:MM:ss")

Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL DateTime format for Excel fmoon606 XSLT 8 May 23rd, 2008 05:35 PM
Convert DateTime Format dnyanubhamare C# 2005 2 February 25th, 2008 09:06 AM
hi! datetime format question.. xkorakidis JSP Basics 0 January 10th, 2008 06:17 AM
Datagrid / DateTime Format Setting tanakrita ASP.NET 1.0 and 1.1 Basics 2 May 17th, 2007 09:56 PM
DateTime format quirks ADMystery ASP.NET 1.0 and 1.1 Professional 5 September 18th, 2006 06:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.