Solved

datagrid formatting problem!

Posted on 2002-03-13
6
209 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 50

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

809 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