473,606 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FormatDateTime

I have a web page field formatted with FormatDateTime( mydate,2) and when the
column is NULL the report shows 1/1/0001

Thanks

David
Oct 16 '07 #1
2 4482
On Oct 16, 3:11 pm, "David C" <dlch...@lifeti meinc.comwrote:
I have a web page field formatted with FormatDateTime( mydate,2) and when the
column is NULL the report shows 1/1/0001

Thanks

David
What I would do, David, is to write a server-side function that takes
an object as input. Pass the datefield to this function. The
function then checks to see if the object is null. If so, the
function should return whatever string you figure you want or even ""
so that nothing prints out for date if the date is null.
If the object isn't null, then cast it to a string and then do
whatever date formatting you need to do, and return this string.
It'll work just fine.

I've done this calling it from server side. I've also done this
client side on other types of data. Here's an example:

Text='<%# Cnote.CaseNoteT ypeDescription( DataBinder.Eval (Container,
"DataItem.Cnote Type")) %>'

Public Function CaseNoteTypeDes cription(ByVal obj As Object) As
String
Dim strReturn As String = String.Empty
Dim strCode As String

If (obj Is Nothing) Then
Return String.Empty
End If
strCode = obj.ToString()

If (strCode = String.Empty) Then
Return String.Empty
End If

If (pCaseNotesType Codes Is Nothing) Then
pCaseNotesTypeC odes = New Hashtable
End If

If (pCaseNotesType Codes.Contains( strCode)) Then
Return pCaseNotesTypeC odes.Item(strCo de)
End If
Dim CnoteType As ComitData.LOOKU P_CASE_NOTE_TYP E

Try
CnoteType =
ComitData.LOOKU P_CASE_NOTE_TYP E.Retrieve(strC ode)
Catch ex As Exception
AppErrorLog.Log ("CaseNoteTy pe bad", "Case note type is
note listed in the lookup table: " & strCode,
System.Environm ent.UserName, True)
Return String.Empty
End Try
strReturn = CnoteType.Descr iption + ""
pCaseNotesTypeC odes.Add(strCod e, strReturn)

Return strReturn
End Function

I've done this plenty of times. You can call your function from
inside a gridview. You can call it from the text property of a
textbox or a label or whatever control you want. As you can see, by
passing the raw database field in as an object, it wont break if the
data item is null. You can check it safely and format it according to
whatever rules you feel you want.
Good luck.

Oct 16 '07 #2
Thanks, I'll give it a try.
"HockeyFan" <le**********@g mail.comwrote in message
news:11******** **************@ q3g2000prf.goog legroups.com...
On Oct 16, 3:11 pm, "David C" <dlch...@lifeti meinc.comwrote:
>I have a web page field formatted with FormatDateTime( mydate,2) and when
the
column is NULL the report shows 1/1/0001

Thanks

David

What I would do, David, is to write a server-side function that takes
an object as input. Pass the datefield to this function. The
function then checks to see if the object is null. If so, the
function should return whatever string you figure you want or even ""
so that nothing prints out for date if the date is null.
If the object isn't null, then cast it to a string and then do
whatever date formatting you need to do, and return this string.
It'll work just fine.

I've done this calling it from server side. I've also done this
client side on other types of data. Here's an example:

Text='<%# Cnote.CaseNoteT ypeDescription( DataBinder.Eval (Container,
"DataItem.Cnote Type")) %>'

Public Function CaseNoteTypeDes cription(ByVal obj As Object) As
String
Dim strReturn As String = String.Empty
Dim strCode As String

If (obj Is Nothing) Then
Return String.Empty
End If
strCode = obj.ToString()

If (strCode = String.Empty) Then
Return String.Empty
End If

If (pCaseNotesType Codes Is Nothing) Then
pCaseNotesTypeC odes = New Hashtable
End If

If (pCaseNotesType Codes.Contains( strCode)) Then
Return pCaseNotesTypeC odes.Item(strCo de)
End If
Dim CnoteType As ComitData.LOOKU P_CASE_NOTE_TYP E

Try
CnoteType =
ComitData.LOOKU P_CASE_NOTE_TYP E.Retrieve(strC ode)
Catch ex As Exception
AppErrorLog.Log ("CaseNoteTy pe bad", "Case note type is
note listed in the lookup table: " & strCode,
System.Environm ent.UserName, True)
Return String.Empty
End Try
strReturn = CnoteType.Descr iption + ""
pCaseNotesTypeC odes.Add(strCod e, strReturn)

Return strReturn
End Function

I've done this plenty of times. You can call your function from
inside a gridview. You can call it from the text property of a
textbox or a label or whatever control you want. As you can see, by
passing the raw database field in as an object, it wont break if the
data item is null. You can check it safely and format it according to
whatever rules you feel you want.
Good luck.

Oct 17 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7822
by: Jay | last post by:
I previously posted this question under Visual Basic newsgroup, but was advised to re-post here. I'm hoping someone can help me solve an issue I'm having with VB.Net and Access 2000. Here's the issue. I hope I've included all relevant information. On a form, I have a DateTimePicker with the following
6
1650
by: Thomas Scheiderich | last post by:
I have the following page as test.aspx: *************************************************** <html> <head> <title>Hello and Welcome Page</title> </head> <body> <center> <% Dim CurrentDate As String
4
2060
by: Sune | last post by:
Hi, Is there any way to define the default date/time format, instead of having to format every single time you print a date/time? Thanks -- Regards, Sune
12
3837
by: DC Gringo | last post by:
How can I convert this pubLatest to a date with format "m/d/yyyy"? Dim pubLatest As New Date pubLatest = Me.SqlSelectCommand1.Parameters("@pubLatest").Value -- _____ DC G
10
3569
by: John K | last post by:
I recently took a job doing PHP but come from an ASP background. I'm trying to find a conversion equivalent for VBScript's "formatdatetime". All I want to do is convert a MySQL datetime field into a long date. e.g. 2006-01-30 to January 1, 2006. PLEASE provide an example that I can use as a future benchmark so I can understand the syntax better. I really need to learn PHP and I'm a
5
3726
by: John K | last post by:
I posted on this a week or so ago and found a resolution in that instance by using DATE_FORMAT in my sql string to display the format I was looking for. This time I need to format the date going "into" the database. In ASP/VBScript I just use "FormatDateTime" to convert the users input into a palatable MySQL "date" datatype. Here's what I need... The user inputs a date by selecting dropboxes for "month", "day", and "year". I did this...
2
9814
by: fiefie.niles | last post by:
I set my computer Regional Setting (Control Panel - Regional and Language Options - Customize - Date) to dd/mm/yy. In my ASP page I do the following: FormatDateTime("1/20/07",2) and it returns 1/20/07 instead of 20/1/07. I though my setting it to 2, it will display a date using the short date format specified in your computer's regional settings, how come
1
12913
by: nitinkeser | last post by:
how i convert date into specific format in asp? like in date format 'Jun 17, 2007' ?
1
3531
by: janetopps | last post by:
This is an asp page which adds a template to a mysql database. it returns this error Microsoft VBScript runtime error '800a000d' Type mismatch: 'FormatDateTime' /temps.asp, line 111
0
8010
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8433
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8429
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8084
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6761
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5963
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3922
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3969
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.