Solved

datagrid formatting problem!

Posted on 2002-03-13
6
207 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 49

Expert Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Expert Comment

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

Author Comment

by:spiral
Comment Utility


the answer which being propose doesnt work
0
 
LVL 1

Accepted Solution

by:
cnealy earned 70 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VB6 convert MSHFlexgrid1 cells no2 2 50
Replace Formatted Numbers with text 9 50
Using "ScreenUpdating" 6 45
Adding to a VBA? 6 46
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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

744 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

16 Experts available now in Live!

Get 1:1 Help Now