Solved

datagrid formatting problem!

Posted on 2002-03-13
6
210 Views
Last Modified: 2010-05-02
i got a datagrid which i want to show the date
as "dd-mm-yyyy hh:mm:ss". the data in the sql server table
is defined as datatime. however, when i select the data
into a datagrid my data->
"01-12-2001 00:00:00" becomes "01-12-2001" in the datagrid. It just never shows the "00:00:00"
but if the data is "01-12-2001 23:59" it shows the data
in its orginal form eg '01-12-2001 23:59". how to solve this problem i have?
0
Comment
Question by:spiral
6 Comments
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 6863251
Not very sure if this can work for SQL Server:

Select Format(myDate,'dd-mm-yyyy hh:mm:ss') As myDate From myTable
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6863451
Well, I just did this:
1. Right click on the grid, select Properties.
2. Click the Format Tab
3. Select the date/time column from Format Item Combo.
4. Select Format Type = Custom
5. Format string text box appears, create a mask.  Mine looks like:
dd-mm-yyyy hh:mm:ss

The column data looks like:
01-02-2002 00:00:00
01-02-2002 01:01:01
02-02-2002 12:59:00
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6863592
Please maintain your open questions:
Questions Asked 17
Last 10 Grades Given B A A B A B B B B  
Question Grading Record 9 Answers Graded / 9 Answers Received

Thanks,
Anthony
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Expert Comment

by:sunyuchen
ID: 6863678
maybe u can try this in sql statement
select convert(varchar, myDate, 109) from tblTime
0
 

Author Comment

by:spiral
ID: 6863711


the answer which being propose doesnt work
0
 
LVL 1

Accepted Solution

by:
cnealy earned 70 total points
ID: 6865377
I'm doing something similar in one of my data grids.   I was able to format a date column by using the StdDataFormat.  Try changing the line where I have objFormat.Format = "mm/dd/yyy" to the format that you want.

Dim objFormat As StdDataFormat 'for using DataFormat

For Each c In dbgCourtHearings.Columns
  Select Case c.DataField
  Case "Court_Date_ID"
    c.Visible = False
  Case "Court_Hearing_Date"
    c.Width = 1100
    Set objFormat = New StdDataFormat
    objFormat.Format = "mm/dd/yyyy"
    Set c.DataFormat = objFormat
  Case "Court_Hearing_Time"
    c.Width = 1000
    'set time format
    Set objFormat = New StdDataFormat
    objFormat.Format = "Medium Time"
    Set c.DataFormat = objFormat
  Case "Hearing_Type_Description"
    c.Width = 2700
  End Select
Next c
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

Suggested Solutions

Title # Comments Views Activity
Spell Check in VB6 13 127
backup program with robocopy 6 45
VBA: loop recent folder and copy txt file. 8 35
Collapse and expand table in Word 2010 2 36
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 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