473,473 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

01/01/ and whatever year is coming as current year -1

34 New Member
Hi all
how to write this 01/01/ and whatever year is coming as current year -1....in an SQL query .i want it to write it in a stored proc... using SQL server 2000.

Thanks in advance .
.
Oct 9 '07 #1
8 5905
iburyak
1,017 Recognized Expert Top Contributor
Try this :


Select '01/01/' + year(getdate())
Oct 9 '07 #2
sanika1507
34 New Member
Try this :


Select '01/01/' + year(getdate())

Thanks a lot for your help but this doesnt work .......like if todays date is 10/09/2007
i want to giv a default date as 01/01/ currentdate -1 ......so tht i get 01/01/2006...Similarly if the current date is 01/01/2008 then also i want 01/01/2007
thnaks in advance
Oct 9 '07 #3
sanika1507
34 New Member
Thanks a lot for your help but this doesnt work .......like if todays date is 10/09/2007
i want to giv a default date as 01/01/ currentdate -1 ......so tht i get 01/01/2006...Similarly if the current date is 01/01/2008 then also i want 01/01/2007
thnaks in advance
plus i m gettin the error as


Syntax error converting the varchar value '01/01/' to a column of data type int.
Oct 9 '07 #4
iburyak
1,017 Recognized Expert Top Contributor
I assume you want to get a date for one year ago.
select dateadd(yy, -1, getdate())


Originaly i thought you want to get a first day of current year.
Like this:

select '01/01/' + convert(varchar(10), year(getdate()))

Goo Luck.
Oct 9 '07 #5
Motoma
3,237 Recognized Expert Specialist
I assume you want to get a date for one year ago.
select dateadd(yy, -1, getdate())


Originaly i thought you want to get a first day of current year.
Like this:

select '01/01/' + convert(varchar(10), year(getdate()))

Goo Luck.
I think it would actually be:
Expand|Select|Wrap|Line Numbers
  1. SELECT '01/01/' + CONVERT(VARCHAR(10), YEAR(GETDATE()) - 1)
  2.  
Oct 9 '07 #6
sanika1507
34 New Member
I think it would actually be:
Expand|Select|Wrap|Line Numbers
  1. SELECT '01/01/' + CONVERT(VARCHAR(10), YEAR(GETDATE()) - 1)
  2.  

Thanks to u . So I am gettint he date as I wanted ....now i have declare the

declare @startdate datetime

Set @startdate =' SELECT +''01/01/'' + CONVERT(VARCHAR(10), YEAR(GETDATE()) - 1)'

but now there is an error because of the mismatch datetime and Varchar ,

hence i used again

set convert (varchar(10),@startdate ,101) = ' SELECT +''01/01/'' + CONVERT(VARCHAR(10), YEAR(GETDATE()) - 1)'

but still there is an error.Imean there is a syntax error .Can anyone please correct it ........
Thanks in advance
Oct 9 '07 #7
Motoma
3,237 Recognized Expert Specialist
Thanks to u . So I am gettint he date as I wanted ....now i have declare the

declare @startdate datetime

Set @startdate =' SELECT +''01/01/'' + CONVERT(VARCHAR(10), YEAR(GETDATE()) - 1)'

but now there is an error because of the mismatch datetime and Varchar ,

hence i used again

set convert (varchar(10),@startdate ,101) = ' SELECT +''01/01/'' + CONVERT(VARCHAR(10), YEAR(GETDATE()) - 1)'

but still there is an error.Imean there is a syntax error .Can anyone please correct it ........
Thanks in advance
The datetime format, when represented as a string looks like this: "2007-10-09 13:18:08.123".
Try "SELECT GETDATE()" to see an example.
Oct 9 '07 #8
ck9663
2,878 Recognized Expert Specialist
Thanks to u . So I am gettint he date as I wanted ....now i have declare the

declare @startdate datetime

Set @startdate =' SELECT +''01/01/'' + CONVERT(VARCHAR(10), YEAR(GETDATE()) - 1)'

but now there is an error because of the mismatch datetime and Varchar ,

hence i used again

set convert (varchar(10),@startdate ,101) = ' SELECT +''01/01/'' + CONVERT(VARCHAR(10), YEAR(GETDATE()) - 1)'

but still there is an error.Imean there is a syntax error .Can anyone please correct it ........
Thanks in advance

defaulting dates to today's date - 1 year:

select @startdate = dateadd(yy, -1, getdate())


defaulting dates to jan 1 of previous year using "mm/dd/yyyy" format as input

select @startdate = convert(datetime, '01/01/' + cast(year(dateadd(yy, -1, getdate())) as char(4)),101)


these are based on current/system date. replace the "getdate()" string with the fieldname or variable name as necessary.
Oct 9 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

72
by: Mel | last post by:
Are we going backwards ? (please excuse my spelling...) In my opinion an absolute YES ! Take a look at what we are doing ! we create TAGS, things like <H1> etc. and although there are tools...
8
by: Zero.NULL | last post by:
Hi, We are using Month-year tables to keep the history of long transaction of our application. For example: We capture the details of a certain action in table...
2
by: Douglas | last post by:
I have a Vehicle MOT field in my table which i have as a Date field I dont really want to hold the year, just 'dd mmm' as MOTs are the same date every year. I have the field on my form as a...
1
by: Terencetrent | last post by:
I have created a query that examines qarterly sales for 5 regions in the country. The query contains data for the past 6 quarters for each region and calculates the perecentage of total sales for...
2
by: Bernd Hohmann | last post by:
Dear collegues, small query problem. A table (simplified example)... customer as char(5) inv_date as date amount as double
3
by: jannoergaard | last post by:
Hi I want to write a function that can return a sum for a given date range. The same function should be able to return the sum for the same period year before. Let me give an example: The...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
1
by: digidave | last post by:
I am keenly aware that my coding skills are extremely noob but please indulge me a second.. Take a look at these queries.. $sql = "SELECT DISTINCT year FROM _current_floats_config WHERE active =...
5
by: Aljosa Mohorovic | last post by:
i use this to find out current week and total number of weeks for current year: now = datetime.now() weeks_in_year = int(date(now.year, 12, 31).strftime("%W")) current_week = int(date(now.year,...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.