Solved

ASP.net VB.net SQL storing date and time

Posted on 2013-10-24
3
485 Views
Last Modified: 2013-10-24
Hi

I have a SQL table with a field that is Date type
I use the following code to get today's date and insert it into the table

Dim strDate As String = Now.Date.ToString

In the table I see eg 12/10/2013 12:00:00

How do I store the date and the exact time of entry?
Also, how do I store just the date in the table?
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Accepted Solution

by:
colly92002 earned 500 total points
ID: 39596879
Have you tried using a format pattern?  
For example something like this:

' Get date now
Dim dispDt As DateTime = DateTime.Now

 ' Set up a date time format
Public Shared datePatt As String = "M/d/yyyy hh:mm:ss tt" 

Dim strDate As String
'Turn date/time into string using patter defined
 strDate = dispDt.ToString(datePatt)

Open in new window

0
 
LVL 33

Expert Comment

by:Big Monty
ID: 39597141
as an alternative, you can get the current date and time directly in your insert sql:

insert into tblName( dateField ), value( getDate() );
0
 

Author Closing Comment

by:Murray Brown
ID: 39597146
thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question