Solved

ASP.net VB.net SQL storing date and time

Posted on 2013-10-24
3
481 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:murbro
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:murbro
ID: 39597146
thanks
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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

730 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