Solved

ASP.net VB.net SQL storing date and time

Posted on 2013-10-24
3
468 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 32

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
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

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now