Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Convert a 'string' to full Date and Time

Posted on 2013-11-28
6
Medium Priority
?
477 Views
Last Modified: 2013-11-28
I am working with Crystal reports 2011 and have a string, which is in the following format - '11/26/2013 7:15:11AM' which I want to convert to a DateTime holding the same format including the (AM/PM)
0
Comment
Question by:John-S Pretorius
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 18

Accepted Solution

by:
vasto earned 1000 total points
ID: 39683865
DateTimeValue({Table.Field})

if this doesn't work try to parse it like this:

DateTime({Table.Field})[7 to 10], {Table.Field})[1 to 2], {Table.Field})[4 to 5] ..... hour ... minute ... sec)
the second approach might be trivy because you may have 1 or 2 characters for month, day and hour . It might be better if you parse by "/" and ":" and combine the values using DateTime
0
 

Author Comment

by:John-S Pretorius
ID: 39683894
This looks good - can I ask if there is a way 'trap' (If statement) that would avoid 'Bad date-time format string' as the current string I'm trying to convert also has some values that cannot be converted to date and time.
0
 

Author Comment

by:John-S Pretorius
ID: 39683910
I found the statement that works : if isdate({table.field}) then DateTimeValue({Table.Field})

Thank you for your help.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:John-S Pretorius
ID: 39683911
I've requested that this question be closed as follows:

Accepted answer: 0 points for johnsp1234's comment #a39683894

for the following reason:

I found the statement that works : if isdate({table.field}) then DateTimeValue({Table.Field})

Thank you for your help.
0
 

Author Closing Comment

by:John-S Pretorius
ID: 39683912
I found the statement that works : if isdate({table.field}) then DateTimeValue({Table.Field})

Thank you for your help.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 39683914
You can do 2 checks

First for NULL - no value then for IsDateTime

If IsNull({DateString}) then
    Date(1900,1,1)
Else If IsDateTime({DateString}) then
    cDateTime({DateString})
Else
    Date(1900,1,1)


If it doesn't like your date format then you will have to use the second version with a minor adjustment.  The values passed must be numbers not a number string

DateTime(Val({Table.Field})[7 to 10]), Val({Table.Field})[1 to 2]), Val({Table.Field})[4 to 5]) ..... hour ... minute ... sec)


mlmcc
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

647 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