473,608 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need to convert a date and time to a different format


Precisely, here's what I need:

When I run getdate(), I get, for example:

August 9 2004 5:17 P.M.

I want to turn the date portion into:

8/9/2004 format and update one column with it
I want to turn 5:17 P.M. into:

hhmmss and update another column with it.
I've been playing around with datepart, with substr, with you name it,
and I'm stumped.

Any code samples, other help most appreciated.

Thanks,
Google Jenny

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
1 2225
Hi

If you column is a datetime data type then there will always be a time
portion. Not specifying the time when you update the field will default it
to 00:00:00. To return a string representation of the date and time you can
use the CONVERT function to specify a format. See the topic "CAST and
CONVERT" in books online. Use the REPLACE function if you want to strip out
the colons.

DECLARE @myDate datetime
SET @myDate = '20040809 17:17'

SELECT @myDate, CONVERT(char(10 ),@myDate,101) + ' ' +
REPLACE(CONVERT (char(8),@myDat e,108),':','')

John

"Google Jenny" <mi******@yahoo .com> wrote in message
news:41******** **************@ news.newsgroups .ws...

Precisely, here's what I need:

When I run getdate(), I get, for example:

August 9 2004 5:17 P.M.

I want to turn the date portion into:

8/9/2004 format and update one column with it
I want to turn 5:17 P.M. into:

hhmmss and update another column with it.
I've been playing around with datepart, with substr, with you name it,
and I'm stumped.

Any code samples, other help most appreciated.

Thanks,
Google Jenny

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #2

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

Similar topics

2
3639
by: | last post by:
First of all, I want to know if Cookie's expiration time and HTTP's header's last modified time are using the same format. Secondly, how do I format the time from a 10923023324324 kind of number into the cookie and http header format(s)?
3
2327
by: Ralf Meuser | last post by:
Hi there, I get form a database time with the format : 'Jan 01 1900 06:00PM' I want to convert it to :HH:MM I tryed it with $heure=(date("H:i",strtotime($row)) but I get allways 20:55. even when time changes. Whats wrong ? Does anybody know where I can get a good function which will convert date to
7
5150
by: Nimmy | last post by:
Hi, I have a file which has different dates, I want to scanf them as CHAR and convert them to DATE format, how can I do this? Thanks
9
25022
by: romy | last post by:
It used to work in vb6. I don't know the syntax in vb.net current date and time.... format (cstr(date),"DDMMYY") format(cstr(time),"HHMM") thanks
2
1486
by: phillip.s.powell | last post by:
I have to migrate data from one database table to another table in another database where the fields do not match, not even in the same order, and even if they do match, on occasions the datatypes are completely different (varchar vs int, varchar vs char, int vs datetime, etc.). I am expected to do this immediately so this is an emergency request. Help!
10
162648
by: bonnie.tangyn | last post by:
Dear all In my ASP page, user can enter date in dd/mm/yyyy format. How can I use Javascript to convert dd/mm/yyyy to yyyy-mm-dd hh:mm:ss. Please give me some advices. Cheers Bon
2
11994
by: kirke | last post by:
Hi, I have a datetime column named dtDateTime. its format is "Oct 27 2006 12:00:00 " I want to group by only date part of it and count my code is $sql1="SELECT convert(varchar,J1708Data.dtDateTime,120), count(convert(varchar,J1708Data.dtDateTime,120))
2
3145
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button then the calender gone actually i want if i click outside off the calender then it should me removed ..How kan i do this ... Pls inform me as early as possible .. I am waiting for ur quick replay ...Here i attached the source code .... <!DOCTYPE...
13
15790
by: baldrex | last post by:
hmm... I have something similar to this but in my case this will not work. I have a text field storing the value in mins in this format 000100 representing 1 min. I need to break this into a time reference 00:01:00 so that I can use it to calculate total time spent. I have tried several different date/time functions but they all add the date, which I do not need. question is: is there a way to convert this text into a time only...
0
8063
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
8003
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8498
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
8478
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...
0
3962
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
4025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1598
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1331
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.