Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: entering correct date


Message #1 by soni29@h... on Mon, 20 May 2002 21:50:45
hi,
i had a slight problem with date, i'm making a page where the user is able 
to purchase goods, once completed and accepted the date of purchase should 
be entered into the database in a table.  i used the code that was given 
in the beg. asp.net book but i keep getting the date around the year 1899, 
not sure why? here is the code for that page:

<%@ Page Language="VB" aspcompat=true Debug=true%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Oledb" %>

<Script language="VB" Runat="Server">
Sub Page_Load()
  Dim objCC As Object
  Dim strCardNumber As String
  Dim blnIsValid, blnApproved As Boolean
  Dim strConnection, strSQL as String
  Dim objConnection as Object
  Dim objCommand as oledbCommand
  Dim dtoday, temptoday as Date						' 
Two Date variables
  Dim strToday as String						
	' A string to hold today's date
 
  If Len(Request("CardNumber")) > 0 Then			' Is the 
number blank?
    strCardNumber = Request("CardNumber")
    blnIsValid = True
  Else 
    blnIsValid = False
  End If

  if blnIsValid Then						
    objCC = Server.CreateObject("CCObject.ProcessCard")		' Create 
an instance of the object
    blnApproved = objCC.IsValidCreditCardNumber(strCardNumber)	' Get 
approval
  End If

  If blnApproved Then
    dtoday = Now()				' Get the date and time
    temptoday = GetOnlyDate(dtoday)		' Get only the date, chop 
off time portion
    strToday = CStr(temptoday)		' Cast Date to String  
    strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data 
Source=C:\BegASPNET\Assign5\CIS433.mdb"
    strSQL = "Insert into CustomerOrder(UserNumber, TotalAmount, 
DateAdded) values (" + CStr(Session("UserID")) _
		   + ", " + CStr(Session("TotalAmount")) + ", " + strToday 
+ ")"
   
    Result.Text = "Your card was approved, Thank you." 			
		' Card was approved
    
    objConnection = New OledbConnection(strConnection)			
		' Create the connection
    objCommand = New OledbCommand(strSQL, objConnection)		
		' Create the command
    objConnection.Open()						
						' Open the connection
    objCommand.ExecuteNonQuery()					
					' Insert data into table
    
    objConnection.close()						
						' Close the connection
  Else
    Result.Text = "<b><font color = red>Sorry, but your card was 
declined</font></b>"					' Card was declined
  End If
End Sub

' Function used to chop of time and return only the date portion of a Date 
object
Function GetOnlyDate(dtoday as Date) As Date
	Return DateValue(DateAdd("d", 0, dtoday))
End Function
</Script>

<HTML>
<HEAD></HEAD>
<BODY>

<asp:Label id="Result" Runat="Server" />

</BODY>
</HTML>

Thank you.
Message #2 by <kshatdalpriya@i...> on Tue, 21 May 2002 13:11:17 +0530
hi soni,
I think the date u get is not proper format as u make a string so SQL Server
will take 1899 data format , try to using mm/dd/yyyy format.


-----Original Message-----
From: soni29@h... [mailto:soni29@h...]
Sent: Monday, May 20, 2002 9:51 PM
To: ASP+
Subject: [aspx] entering correct date


hi,
i had a slight problem with date, i'm making a page where the user is able
to purchase goods, once completed and accepted the date of purchase should
be entered into the database in a table.  i used the code that was given
in the beg. asp.net book but i keep getting the date around the year 1899,
not sure why? here is the code for that page:

<%@ Page Language="VB" aspcompat=true Debug=true%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Oledb" %>

<Script language="VB" Runat="Server">
Sub Page_Load()
  Dim objCC As Object
  Dim strCardNumber As String
  Dim blnIsValid, blnApproved As Boolean
  Dim strConnection, strSQL as String
  Dim objConnection as Object
  Dim objCommand as oledbCommand
  Dim dtoday, temptoday as Date						'
Two Date variables
  Dim strToday as String
	' A string to hold today's date

  If Len(Request("CardNumber")) > 0 Then			' Is the
number blank?
    strCardNumber = Request("CardNumber")
    blnIsValid = True
  Else
    blnIsValid = False
  End If

  if blnIsValid Then
    objCC = Server.CreateObject("CCObject.ProcessCard")		' Create
an instance of the object
    blnApproved = objCC.IsValidCreditCardNumber(strCardNumber)	' Get
approval
  End If

  If blnApproved Then
    dtoday = Now()				' Get the date and time
    temptoday = GetOnlyDate(dtoday)		' Get only the date, chop
off time portion
    strToday = CStr(temptoday)		' Cast Date to String
    strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\BegASPNET\Assign5\CIS433.mdb"
    strSQL = "Insert into CustomerOrder(UserNumber, TotalAmount,
DateAdded) values (" + CStr(Session("UserID")) _
		   + ", " + CStr(Session("TotalAmount")) + ", " + strToday
+ ")"

    Result.Text = "Your card was approved, Thank you."
		' Card was approved

    objConnection = New OledbConnection(strConnection)
		' Create the connection
    objCommand = New OledbCommand(strSQL, objConnection)
		' Create the command
    objConnection.Open()
						' Open the connection
    objCommand.ExecuteNonQuery()
					' Insert data into table

    objConnection.close()
						' Close the connection
  Else
    Result.Text = "<b><font color = red>Sorry, but your card was
declined</font></b>"					' Card was declined
  End If
End Sub

' Function used to chop of time and return only the date portion of a Date
object
Function GetOnlyDate(dtoday as Date) As Date
	Return DateValue(DateAdd("d", 0, dtoday))
End Function
</Script>

<HTML>
<HEAD></HEAD>
<BODY>

<asp:Label id="Result" Runat="Server" />

</BODY>
</HTML>

Thank you.


  Return to Index